mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-05 20:08:58 -05:00
@@ -393,6 +393,12 @@
|
||||
],
|
||||
"description": "%typescript.tsc.autoDetect%",
|
||||
"scope": "resource"
|
||||
},
|
||||
"typescript.quickSuggestionsForPaths": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%typescript.quickSuggestionsForPaths%",
|
||||
"scope": "resource"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -571,4 +577,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,5 +41,6 @@
|
||||
"javascript.nameSuggestions": "Enable/disable including unique names from the file in JavaScript suggestion lists.",
|
||||
"typescript.tsc.autoDetect": "Controls auto detection of tsc tasks. 'off' disables this feature. 'build' only creates single run compile tasks. 'watch' only creates compile and watch tasks. 'on' creates both build and watch tasks. Default is 'on'.",
|
||||
"typescript.problemMatchers.tsc.label": "TypeScript problems",
|
||||
"typescript.problemMatchers.tscWatch.label": "TypeScript problems (watch mode)"
|
||||
"typescript.problemMatchers.tscWatch.label": "TypeScript problems (watch mode)",
|
||||
"typescript.quickSuggestionsForPaths": "Enable/disable quick suggestions when typing out an import path."
|
||||
}
|
||||
|
||||
@@ -122,34 +122,36 @@ class MyCompletionItem extends CompletionItem {
|
||||
interface Configuration {
|
||||
useCodeSnippetsOnMethodSuggest: boolean;
|
||||
nameSuggestions: boolean;
|
||||
quickSuggestionsForPaths: boolean;
|
||||
}
|
||||
|
||||
namespace Configuration {
|
||||
export const useCodeSnippetsOnMethodSuggest = 'useCodeSnippetsOnMethodSuggest';
|
||||
export const nameSuggestions = 'nameSuggestions';
|
||||
export const quickSuggestionsForPaths = 'quickSuggestionsForPaths';
|
||||
}
|
||||
|
||||
export default class TypeScriptCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
private config: Configuration;
|
||||
private config: Configuration = {
|
||||
useCodeSnippetsOnMethodSuggest: false,
|
||||
nameSuggestions: true,
|
||||
quickSuggestionsForPaths: true
|
||||
};
|
||||
|
||||
constructor(
|
||||
private client: ITypescriptServiceClient,
|
||||
private typingsStatus: TypingsStatus
|
||||
) {
|
||||
this.config = {
|
||||
useCodeSnippetsOnMethodSuggest: false,
|
||||
nameSuggestions: true
|
||||
};
|
||||
}
|
||||
) { }
|
||||
|
||||
public updateConfiguration(): void {
|
||||
// Use shared setting for js and ts
|
||||
const typeScriptConfig = workspace.getConfiguration('typescript');
|
||||
this.config.useCodeSnippetsOnMethodSuggest = typeScriptConfig.get(Configuration.useCodeSnippetsOnMethodSuggest, false);
|
||||
|
||||
const jsConfig = workspace.getConfiguration('javascript');
|
||||
this.config.nameSuggestions = jsConfig.get(Configuration.nameSuggestions, true);
|
||||
this.config.useCodeSnippetsOnMethodSuggest = typeScriptConfig.get<boolean>(Configuration.useCodeSnippetsOnMethodSuggest, false);
|
||||
this.config.quickSuggestionsForPaths = typeScriptConfig.get<boolean>(Configuration.quickSuggestionsForPaths, true);
|
||||
|
||||
this.config.nameSuggestions = workspace.getConfiguration('javascript').get(Configuration.nameSuggestions, true);
|
||||
}
|
||||
|
||||
public provideCompletionItems(
|
||||
@@ -175,6 +177,10 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||
}
|
||||
|
||||
if (context.triggerCharacter === '"' || context.triggerCharacter === '\'') {
|
||||
if (!this.config.quickSuggestionsForPaths) {
|
||||
return Promise.resolve<CompletionItem[]>([]);
|
||||
}
|
||||
|
||||
// make sure we are in something that looks like the start of an import
|
||||
const line = document.lineAt(position.line).text.slice(0, position.character);
|
||||
if (!line.match(/\b(from|import)\s*["']$/) && !line.match(/\b(import|require)\(['"]$/)) {
|
||||
@@ -183,6 +189,10 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||
}
|
||||
|
||||
if (context.triggerCharacter === '/') {
|
||||
if (!this.config.quickSuggestionsForPaths) {
|
||||
return Promise.resolve<CompletionItem[]>([]);
|
||||
}
|
||||
|
||||
// make sure we are in something that looks like an import path
|
||||
const line = document.lineAt(position.line).text.slice(0, position.character);
|
||||
if (!line.match(/\bfrom\s*["'][^'"]*$/) && !line.match(/\b(import|require)\(['"][^'"]*$/)) {
|
||||
|
||||
Reference in New Issue
Block a user