Skip to content

Commit

Permalink
Merge pull request #67 from Aleksandaar/feat_display_workspace_folder…
Browse files Browse the repository at this point in the history
…_option

Add new config option for displaying workspace name
  • Loading branch information
joshmu authored Oct 10, 2024
2 parents 874eb82 + c4541a3 commit c4655d8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ For optimal performance, ensure that the VSCode configuration _Editor: Enable Pr
- `rgMenuActions`: Create menu items which can be selected prior to any query, these items will be added to the ripgrep command to generate the results. Eg: Add `{ "label": "JS/TS", "value": "--type-add 'jsts:*.{js|ts|tsx|jsx}' -t jsts" },` as a menu option to only show js & ts files in the results.
- `rgQueryParams`: Match ripgrep parameters from the input query directly. E.g: `{ "regex": \"^(.+) -t ?(\\w+)$\", "param": \"-t $1\" },` will translate the query `hello -t rust` to `rg 'hello' -t rust` to enable a filetype filter.
- `rgQueryParamsShowTitle`: When a ripgrep parameter match from the list in `rgQueryParams`, the quick pick will show the matched result as a preview in the title bar.
- `showWorkspaceFolderInFilePath`: Include workspace folder name in the folder depth display.
- `startFolderDisplayIndex`: The folder index to display in the results before '...'.
- `startFolderDisplayDepth`: The folder depth to display in the results before '...'.
- `endFolderDisplayDepth`: The folder depth to display in the results after '...'.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@
"default": 4,
"description": "The folder depth to display in the results after truncating with '...'."
},
"periscope.showWorkspaceFolderInFilePath": {
"type": "boolean",
"default": true,
"description": "Include workspace folder name in the folder depth display."
},
"periscope.alwaysShowRgMenuActions": {
"type": "boolean",
"default": true,
Expand Down
12 changes: 10 additions & 2 deletions src/utils/formatPathLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ export function formatPathLabel(filePath: string) {
workspaceFolders.find((folder) => filePath.startsWith(folder.uri.fsPath)) || workspaceFolders[0];

const workspaceFolderName = workspaceFolder.name;
const relativeFilePath = path.relative(workspaceFolder.uri.fsPath, filePath);
const folders = [workspaceFolderName, ...relativeFilePath.split(path.sep)];
let relativeFilePath;
let folders;

if (config.showWorkspaceFolderInFilePath) {
relativeFilePath = path.relative(workspaceFolder.uri.fsPath, filePath);
folders = [workspaceFolderName, ...relativeFilePath.split(path.sep)];
} else {
relativeFilePath = path.relative(workspaceFolder.uri.fsPath, filePath).replace(/(\.\.\/)+/, '');
folders = [...relativeFilePath.split(path.sep)];
}

// abbreviate path if too long
if (folders.length > config.startFolderDisplayDepth + config.endFolderDisplayDepth) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type ConfigItems =
| 'rgQueryParams'
| 'rgQueryParamsShowTitle'
| 'rgPath'
| 'showWorkspaceFolderInFilePath'
| 'startFolderDisplayDepth'
| 'startFolderDisplayIndex'
| 'endFolderDisplayDepth'
Expand All @@ -32,6 +33,7 @@ export function getConfig() {
rgQueryParams: vsConfig.get<{ param?: string; regex: string }[]>('rgQueryParams', []),
rgQueryParamsShowTitle: vsConfig.get<boolean>('rgQueryParamsShowTitle', true),
rgPath: vsConfig.get<string | undefined>('rgPath', undefined),
showWorkspaceFolderInFilePath: vsConfig.get<boolean>('showWorkspaceFolderInFilePath', true),
startFolderDisplayIndex: vsConfig.get<number>('startFolderDisplayIndex', 0),
startFolderDisplayDepth: vsConfig.get<number>('startFolderDisplayDepth', 1),
endFolderDisplayDepth: vsConfig.get<number>('endFolderDisplayDepth', 4),
Expand Down

0 comments on commit c4655d8

Please sign in to comment.