Skip to content

Commit

Permalink
tweak setting for #5312, fyi @usernamehw
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 13, 2020
1 parent 336b58c commit 3d8ad7d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
13 changes: 9 additions & 4 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
33 changes: 22 additions & 11 deletions src/vs/editor/common/services/editorWorkerServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,33 @@ class WordBasedCompletionItemProvider implements modes.CompletionItemProvider {
}

async provideCompletionItems(model: ITextModel, position: Position): Promise<modes.CompletionList | undefined> {
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<WordBasedSuggestionsConfig>(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);
}
}
}

Expand Down

0 comments on commit 3d8ad7d

Please sign in to comment.