mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
@@ -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