diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index f9bf0b49449a3..77fae2b4026fe 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -502,10 +502,15 @@ const editorConfiguration: IConfigurationNode = { default: true, description: nls.localize('wordBasedSuggestions', "Controls whether completions should be computed based on words in the document.") }, - 'editor.wordBasedSuggestionsOnlySameLanguage': { - type: 'boolean', - default: true, - description: nls.localize('wordBasedSuggestionsOnlySameLanguage', "Controls whether word based completions should be included from opened documents of the same language or any language.") + 'editor.wordBasedSuggestionsMode': { + enum: ['currentDocument', 'matchingDocuments', 'allDocuments'], + default: 'matchingDocuments', + enumDescriptions: [ + nls.localize('wordBasedSuggestionsMode.currentDocument', 'Only suggest words from the active document.'), + nls.localize('wordBasedSuggestionsMode.matchingDocuments', 'Suggest words from all open documents of the same language.'), + nls.localize('wordBasedSuggestionsMode.allDocuments', 'Suggest words from all open documents.') + ], + description: nls.localize('wordBasedSuggestionsMode', "Controls form what documents word based completions are computed.") }, 'editor.semanticHighlighting.enabled': { enum: [true, false, 'configuredByTheme'], diff --git a/src/vs/editor/common/services/editorWorkerServiceImpl.ts b/src/vs/editor/common/services/editorWorkerServiceImpl.ts index 72508f18d1995..dc6a0f706a688 100644 --- a/src/vs/editor/common/services/editorWorkerServiceImpl.ts +++ b/src/vs/editor/common/services/editorWorkerServiceImpl.ts @@ -148,22 +148,33 @@ class WordBasedCompletionItemProvider implements modes.CompletionItemProvider { } async provideCompletionItems(model: ITextModel, position: Position): Promise { - const { wordBasedSuggestions, wordBasedSuggestionsOnlySameLanguage } = this._configurationService.getValue<{ wordBasedSuggestions?: boolean, wordBasedSuggestionsOnlySameLanguage?: boolean }>(model.uri, position, 'editor'); - if (!wordBasedSuggestions) { + type WordBasedSuggestionsConfig = { + wordBasedSuggestions?: boolean, + wordBasedSuggestionsMode?: 'currentDocument' | 'matchingDocuments' | 'allDocuments' + }; + const config = this._configurationService.getValue(model.uri, position, 'editor'); + if (!config.wordBasedSuggestions) { return undefined; } const models: URI[] = []; - for (let candidate of this._modelService.getModels()) { - if (!canSyncModel(this._modelService, candidate.uri)) { - continue; + if (config.wordBasedSuggestionsMode === 'currentDocument') { + // only current file and only if not too large + if (canSyncModel(this._modelService, model.uri)) { + models.push(model.uri); } - if (candidate === model) { - models.unshift(candidate.uri); - } else if (!wordBasedSuggestionsOnlySameLanguage) { - models.push(candidate.uri); - } else if (candidate.getLanguageIdentifier().id === model.getLanguageIdentifier().id) { - models.push(candidate.uri); + } else { + // either all files or files of same language + for (const candidate of this._modelService.getModels()) { + if (!canSyncModel(this._modelService, candidate.uri)) { + continue; + } + if (candidate === model) { + models.unshift(candidate.uri); + + } else if (config.wordBasedSuggestionsMode === 'allDocuments' || candidate.getLanguageIdentifier().id === model.getLanguageIdentifier().id) { + models.push(candidate.uri); + } } }