Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Release v0.0.4
Browse files Browse the repository at this point in the history
    - Added a demo screencapture
    - Introduce recently opened files option with 5 hard coded recent files
    - Introduce an output channel for logging
    - Update the `QuickPick` results to display `Label`, `Description` and
  `Details`
    - Ability to search all three fields Label, Description and Details
    for a file entry
    - Disabled caching until a better caching mechanism is introduced.
  • Loading branch information
Gayan committed Jul 22, 2017
1 parent f022412 commit 8cf21b9
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ Fuzzy File Search Visual Studio Code Extension ChangeLog
- Experience is more similar to how Sublime Text of fzf extension works on zsh or bash
- Only tested on Linux / OSX enviorments, ideally might be unstable within windows enviorments.
- By default the extension ignores .git and .vscode directories. But doesn't ignore vendor directories. This is intentional for now. Will be introducing excluded directories via settings in the future.


## [v0.0.4]
- Added a demo screencapture
- Introduce recently opened files option with 5 hard coded recent files
- Introduce an output channel for logging
- Update the `QuickPick` results to display `Label`, `Description` and `Details`
- Ability to search all three fields Label, Description and Details for a file entry
- Disabled caching until a better caching mechanism is introduced.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ Since VSCodes `CMD + P` tends to be quite slow sometimes. This extension can be
## Features

- Ability to fuzzy search trough the project files
- Last 5 open files gets higher priority in the initial result set for quick opens.

![Alt text](/assets/fuzzy-demo.gif?raw=true "Demo 1")

![Alt text](/assets/fuzzy-demo-2.gif?raw=true "Demo 2")

## Requirements

- As of now only requirement is shelljs `.find()` method works on your enviorment. Since this extension has only been tested on Linux and OSX support for Windows it yet to be added once significant test data is present. PR's are welcom.

## Known Issues

Might not work on Windows Operating systems.
- Might not work on Windows Operating systems.
- The `QuickPicker` performs slow with larger projects (50,000++ files), since th Visual Studio API doesn't offer a dynamic update for the input selection as of today. We are still looking out for a suitable solution to make it work best.

## Release Notes

This is a pre-release of the extension and the extension is still under development. Please expect failures.

Please report issues or raise a PR for any contributions against https://github.com/gayanhewa/vscode-fuzzysearch

**Enjoy!**
Binary file added assets/fuzzy-demo-2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fuzzy-demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"name": "fuzzysearch",
"displayName": "Fuzzy File Search",
"description": "Fuzzy file search for the active workspace",
"version": "0.0.3",
"repository": {
"type": "git",
"url": "https://github.com/gayanhewa/vscode-fuzzysearch"
},
"version": "0.0.4",
"publisher": "gayanhewa",
"engines": {
"vscode": "^1.13.0"
Expand All @@ -11,14 +15,19 @@
"Other"
],
"activationEvents": [
"onCommand:extension.fuzzySearch"
"onCommand:extension.fuzzySearch",
"onCommand:extension.fuzzySearchFlush"
],
"main": "./out/src/fuzzysearch",
"contributes": {
"commands": [
{
"command": "extension.fuzzySearch",
"title": "Fuzzy File Search"
},
{
"command": "extension.fuzzySearchFlush",
"title": "Fuzzy File Search Flush Cache"
}
]
},
Expand Down
117 changes: 95 additions & 22 deletions src/fuzzysearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,77 @@
import * as vscode from 'vscode';
import * as shelljs from 'shelljs';

let cache = [];

export function activate(context: vscode.ExtensionContext) {
let ch = vscode.window.createOutputChannel('Fuzzy Search Logs');

let disposable = vscode.commands.registerCommand('extension.fuzzySearch', async () => {
let disposableFuzzySearchCommand = vscode.commands.registerCommand('extension.fuzzySearch', async () => {

if (vscode.workspace.rootPath === undefined) {
vscode.window.showErrorMessage('Unable to use Fuzzy search extension without an active project open.');
return;
}
// Populate a recently viewed file list for the QuickPick dropdown
vscode.workspace.onDidOpenTextDocument((file) => {
console.log(file);

const filelist = await getFileList(vscode.workspace.rootPath);
let fileName = file.fileName;

if (filelist.length < 1) {
vscode.window.showInformationMessage("Empty workspace");
return;
}
console.log(filelist);
vscode.window.showQuickPick(filelist).then((file_selection) => {
if (!shelljs.test('-f', fileName)) {
console.log(shelljs.test('-f', fileName));
console.log('Path is not a valid filename', fileName);
return;
}

const item = {
'label' : "Recent: "+fileName.split('/')[fileName.split('/').length-1],
'description' : fileName.split('/').splice(0,fileName.split('/').length-1).join('/'),
'detail': fileName
};

let files = context.workspaceState.get('modified_files', []);

let updated = false;

files.forEach((v,i) => {
if (files[i].label === item.label) {
updated = true;
files[i] = item;
}
});

if (!updated) {
files.push(item);
}

context.workspaceState.update('modified_files', files.slice(-5));
});

// if (vscode.workspace.rootPath === undefined) {
// vscode.window.showErrorMessage('Unable to use Fuzzy search extension without an active project open.');
// return;
// }

ch.appendLine("Fetching files ...");

let all_filelist = await getFileList(context.asAbsolutePath('/'));
let recent_filelist = context.workspaceState.get('modified_files', []);

let filelist = recent_filelist.concat(all_filelist);

ch.appendLine("Number of files in the project : "+filelist.length );

vscode.window.showQuickPick(
filelist,
{
placeHolder: 'Enter filename',
ignoreFocusOut: true,
matchOnDescription: true,
matchOnDetail: true
}
).then((file_selection) => {
console.log(file_selection);
if (file_selection !== undefined) {
const selectedFile = vscode.Uri.file(context.asAbsolutePath(file_selection));
ch.appendLine('Selected File to open : ' + file_selection.label);
if (file_selection.detail !== undefined) {
let file_path = (shelljs.test('-f', context.asAbsolutePath(file_selection.detail))) ? context.asAbsolutePath(file_selection.detail): file_selection.detail;
const selectedFile = vscode.Uri.file(file_path);
vscode.workspace.openTextDocument(selectedFile).then((document) => {
vscode.window.showTextDocument(document);
});
Expand All @@ -31,20 +82,42 @@ export function activate(context: vscode.ExtensionContext) {

});

context.subscriptions.push(disposable);
let disposableFuzzySearchFlushCommand = vscode.commands.registerCommand('extension.fuzzySearchFlush', () => {
cache = [];
context.workspaceState.update('modified_files', []);
});

context.subscriptions.push(disposableFuzzySearchCommand);
context.subscriptions.push(disposableFuzzySearchFlushCommand);
}

export function getFileList(path) {

// if (cache.length>0) {
// console.log('cached result');
// return cache;
// }

shelljs.cd(path);
// shelljs.cd(vscode.workspace.rootPath);
const filelist = shelljs.find('.').filter((file) => {
return file.indexOf('.git') < 0 && file.indexOf('.vscode') < 0 && file !== '.';
let filelist = shelljs.find('.').filter((file) => {
return shelljs.test('-f', file) && !shelljs.test('-L', file) && file.indexOf('.git') < 0 && file.indexOf('.vscode') && file !== '.';
});

return filelist;
}
filelist.forEach((element,index) => {
let item = {
'label' : element.split('/')[element.split('/').length-1],
'description' : element.split('/').splice(0,element.split('/').length-1).join('/'),
'detail': element
}

export function deactivate() {
console.log('Disabled filelist');
filelist[index] = item;
});

cache = filelist;
return cache;
}

export function deactivate(context: vscode.ExtensionContext) {
cache = [];
context.workspaceState.update('modified_files', []);
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"node_modules",
".vscode-test"
]
}
}

0 comments on commit 8cf21b9

Please sign in to comment.