Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multi segment path support #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,58 @@ exports.activate = context => {
}
}

function navigateTo(relavtivePath) {
const selectedPath = path.join(folderPath, relavtivePath);
const selectedFullPath = path.join(workspaceRoot, selectedPath);

// If selected is a folder, traverse it,
// otherwise open file.
fs.stat(selectedFullPath, (statErr, stats) => {
if (stats.isDirectory()) {
searchPath(workspaceName, workspaceRoot, selectedPath);
} else {
lastWorkspaceName = workspaceName;
lastWorkspaceRoot = workspaceRoot;
lastFolder = folderPath;

vscode.workspace.openTextDocument(selectedFullPath, selectedPath)
.then(vscode.window.showTextDocument);
}
});
}

vscode.window.showQuickPick(options, {
placeHolder: path.format({ dir: workspaceName, base: folderPath})

})
.then(selected => {
// node_modules shortcut selected
if (selected === workspaceNodeModules) {
let lastValue;
let lastSelection;
const quickPick = vscode.window.createQuickPick();
quickPick.items = [
...options.map(option => ({label: option})),
{
alwaysShow: true,
label: 'Navigate...'
}
];
quickPick.placeHolder = path.format({ dir: workspaceName, base: folderPath});
quickPick.onDidHide(() => quickPick.dispose());
quickPick.onDidChangeSelection(selection => {
lastSelection = selection[0].label;
});
quickPick.onDidChangeValue(value => {
lastValue = value;
});
quickPick.onDidAccept(() => {
const selected = lastSelection;
if (selected === 'Navigate...') {
// "deep" navigate, using last entered value
navigateTo(lastValue);
} else if (selected === workspaceNodeModules) {
// node_modules shortcut selected
searchPath(workspaceName, workspaceRoot, nodeModulesPath);
} else {
const selectedPath = path.join(folderPath, selected);
const selectedFullPath = path.join(workspaceRoot, selectedPath);

// If selected is a folder, traverse it,
// otherwise open file.
fs.stat(selectedFullPath, (statErr, stats) => {
if (stats.isDirectory()) {
searchPath(workspaceName, workspaceRoot, selectedPath);
} else {
lastWorkspaceName = workspaceName;
lastWorkspaceRoot = workspaceRoot;
lastFolder = folderPath;

vscode.workspace.openTextDocument(selectedFullPath, selectedPath)
.then(vscode.window.showTextDocument);
}
});
navigateTo(selected);
}

});
quickPick.show();
});
};

Expand Down