Skip to content

Commit

Permalink
feat: automatically trigger next suggestion (#195)
Browse files Browse the repository at this point in the history
* feat: automatically trigger next suggestion

#194

* fix(tests): make test less fragile
  • Loading branch information
ChristianKohler authored Jan 21, 2022
1 parent 6e3bb5c commit 051d7c8
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 100 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ Per default, the autocompletion does not add a slash after a directory.
}
```

### Automatically trigger next suggestion

When a suggestion was selected, the next suggestion will automatically pop up.

This setting will override the `autoSlashAfterDirectory` setting.

```javascript
{
"path-intellisense.autoTriggerNextSuggestion": false,
}
```

### Absolute paths

Per default, absolute paths are resolved within the current workspace root path.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
"type": "boolean",
"default": false,
"description": "Ignores tsconfig file for mappings"
},
"path-intellisense.autoTriggerNextSuggestion": {
"type": "boolean",
"default": false,
"description": "Automatically triggers next suggestion after previous suggestion"
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/configuration/configuration.interface.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export interface Config {
autoSlash: boolean;
autoTrigger: boolean;
mappings: Mapping[];
showHiddenFiles: boolean;
withExtension: boolean;
absolutePathToWorkspace: boolean;
absolutePathTo: string|null;
showOnAbsoluteSlash: boolean,
absolutePathTo: string | null;
showOnAbsoluteSlash: boolean;
filesExclude: { [key: string]: string };
}

Expand Down
17 changes: 11 additions & 6 deletions src/configuration/configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ export async function getConfiguration(

return {
autoSlash: cfgExtension["autoSlashAfterDirectory"],
autoTrigger: cfgExtension["autoTriggerNextSuggestion"],
showHiddenFiles: cfgExtension["showHiddenFiles"],
withExtension: cfgExtension["extensionOnImport"],
absolutePathToWorkspace: cfgExtension["absolutePathToWorkspace"],
absolutePathTo: resolveAbsolutePathTo(cfgExtension["absolutePathTo"], workspaceFolder),
absolutePathTo: resolveAbsolutePathTo(
cfgExtension["absolutePathTo"],
workspaceFolder
),
showOnAbsoluteSlash: cfgExtension["showOnAbsoluteSlash"],
filesExclude: cfgGeneral["exclude"],
mappings,
Expand All @@ -34,19 +38,20 @@ async function getMappings(
): Promise<Mapping[]> {
const mappings = parseMappings(configuration["mappings"]);
const ignoreTsConfigBaseUrl = configuration["ignoreTsConfigBaseUrl"];
const tsConfigMappings = await (ignoreTsConfigBaseUrl ? [] : getWorkfolderTsConfigConfiguration(workfolder));
const tsConfigMappings = await (ignoreTsConfigBaseUrl
? []
: getWorkfolderTsConfigConfiguration(workfolder));
const allMappings = [...mappings, ...tsConfigMappings];
return replaceWorkspaceFolder(allMappings, workfolder);
}


function resolveAbsolutePathTo(
cfgPath?: string,
workfolder?: vscode.WorkspaceFolder,
): string|null {
workfolder?: vscode.WorkspaceFolder
): string | null {
const rootPath = workfolder?.uri.path;

return (rootPath && cfgPath)
return rootPath && cfgPath
? replaceWorkspaceFolderWithRootPath(cfgPath, rootPath)
: null;
}
17 changes: 15 additions & 2 deletions src/providers/javascript/createCompletionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,35 @@ export function createPathCompletionItem(
): vscode.CompletionItem {
return fileInfo.isFile
? createFileItem(fileInfo, config, context)
: createFolderItem(fileInfo, config.autoSlash, context.importRange);
: createFolderItem(
fileInfo,
config.autoSlash,
config.autoTrigger,
context.importRange
);
}

function createFolderItem(
fileInfo: FileInfo,
autoSlash: boolean,
autoTrigger: boolean,
importRange: vscode.Range
): vscode.CompletionItem {
var newText = autoSlash ? `${fileInfo.file}/` : `${fileInfo.file}`;
var newText =
autoSlash || autoTrigger ? `${fileInfo.file}/` : `${fileInfo.file}`;

return {
label: fileInfo.file,
kind: vscode.CompletionItemKind.Folder,
sortText: `a_${fileInfo.file}`,
range: importRange,
insertText: newText,
command: autoTrigger
? {
title: "Trigger suggest",
command: "editor.action.triggerSuggest",
}
: undefined,
};
}

Expand Down
Loading

0 comments on commit 051d7c8

Please sign in to comment.