提交 95096bdc 编写于 作者: J Johannes Rieken

implement settings proposal, #9504

上级 6d2013a6
...@@ -780,7 +780,26 @@ const editorConfiguration: IConfigurationNode = { ...@@ -780,7 +780,26 @@ const editorConfiguration: IConfigurationNode = {
'description': nls.localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.") 'description': nls.localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.")
}, },
'editor.wordBasedSuggestions': { 'editor.wordBasedSuggestions': {
'type': 'boolean', 'anyOf': [
'boolean',
{
type: 'object',
properties: {
strings: {
type: 'boolean',
description: nls.localize('wordBasedSuggestions.strings', "Enable word based suggestions inside strings.")
},
comments: {
type: 'boolean',
description: nls.localize('wordBasedSuggestions.comments', "Enable word based suggestions inside comments.")
},
default: {
type: 'boolean',
description: nls.localize('wordBasedSuggestions.default', "Enable word based suggestions outside of strings and comments.")
},
}
}
],
'default': DefaultConfig.editor.wordBasedSuggestions, 'default': DefaultConfig.editor.wordBasedSuggestions,
'description': nls.localize('wordBasedSuggestions', "Enable word based suggestions.") 'description': nls.localize('wordBasedSuggestions', "Enable word based suggestions.")
}, },
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import { BulkListenerCallback } from 'vs/base/common/eventEmitter'; import { BulkListenerCallback } from 'vs/base/common/eventEmitter';
import { MarkedString } from 'vs/base/common/htmlContent'; import { MarkedString } from 'vs/base/common/htmlContent';
import * as types from 'vs/base/common/types'; import * as types from 'vs/base/common/types';
import * as objects from 'vs/base/common/objects';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { ServicesAccessor, IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation'; import { ServicesAccessor, IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation';
...@@ -481,7 +482,7 @@ export interface IEditorOptions { ...@@ -481,7 +482,7 @@ export interface IEditorOptions {
/** /**
* Enable word based suggestions. Defaults to 'true' * Enable word based suggestions. Defaults to 'true'
*/ */
wordBasedSuggestions?: boolean; wordBasedSuggestions?: boolean | { strings?: boolean, comments?: boolean, default?: boolean };
/** /**
* The font size for the suggest widget. * The font size for the suggest widget.
* Defaults to the editor font size. * Defaults to the editor font size.
...@@ -1015,7 +1016,7 @@ export class EditorContribOptions { ...@@ -1015,7 +1016,7 @@ export class EditorContribOptions {
readonly acceptSuggestionOnCommitCharacter: boolean; readonly acceptSuggestionOnCommitCharacter: boolean;
readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none'; readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
readonly emptySelectionClipboard: boolean; readonly emptySelectionClipboard: boolean;
readonly wordBasedSuggestions: boolean; readonly wordBasedSuggestions: boolean | { strings?: boolean, comments?: boolean, default?: boolean };
readonly suggestFontSize: number; readonly suggestFontSize: number;
readonly suggestLineHeight: number; readonly suggestLineHeight: number;
readonly selectionHighlight: boolean; readonly selectionHighlight: boolean;
...@@ -1042,7 +1043,7 @@ export class EditorContribOptions { ...@@ -1042,7 +1043,7 @@ export class EditorContribOptions {
acceptSuggestionOnCommitCharacter: boolean; acceptSuggestionOnCommitCharacter: boolean;
snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none'; snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
emptySelectionClipboard: boolean; emptySelectionClipboard: boolean;
wordBasedSuggestions: boolean; wordBasedSuggestions: boolean | { strings?: boolean, comments?: boolean, default?: boolean };
suggestFontSize: number; suggestFontSize: number;
suggestLineHeight: number; suggestLineHeight: number;
selectionHighlight: boolean; selectionHighlight: boolean;
...@@ -1094,7 +1095,7 @@ export class EditorContribOptions { ...@@ -1094,7 +1095,7 @@ export class EditorContribOptions {
&& this.acceptSuggestionOnCommitCharacter === other.acceptSuggestionOnCommitCharacter && this.acceptSuggestionOnCommitCharacter === other.acceptSuggestionOnCommitCharacter
&& this.snippetSuggestions === other.snippetSuggestions && this.snippetSuggestions === other.snippetSuggestions
&& this.emptySelectionClipboard === other.emptySelectionClipboard && this.emptySelectionClipboard === other.emptySelectionClipboard
&& this.wordBasedSuggestions === other.wordBasedSuggestions && objects.equals(this.wordBasedSuggestions, other.wordBasedSuggestions)
&& this.suggestFontSize === other.suggestFontSize && this.suggestFontSize === other.suggestFontSize
&& this.suggestLineHeight === other.suggestLineHeight && this.suggestLineHeight === other.suggestLineHeight
&& this.selectionHighlight === other.selectionHighlight && this.selectionHighlight === other.selectionHighlight
......
...@@ -77,27 +77,6 @@ export class EditorWorkerServiceImpl implements IEditorWorkerService { ...@@ -77,27 +77,6 @@ export class EditorWorkerServiceImpl implements IEditorWorkerService {
} }
} }
class WordBasedCompletionConfig {
static fromOldConfig(value: boolean): WordBasedCompletionConfig {
return new WordBasedCompletionConfig(value, value, value);
}
constructor(
readonly suggestInStrings: boolean,
readonly suggestInComments: boolean,
readonly suggestInCode: boolean
) {
}
accept(tokenType: modes.StandardTokenType): boolean {
return (tokenType === modes.StandardTokenType.String && this.suggestInStrings)
|| (tokenType === modes.StandardTokenType.Comment && this.suggestInComments)
|| (tokenType === modes.StandardTokenType.Other && this.suggestInCode);
}
}
class WordBasedCompletionItemProvider implements modes.ISuggestSupport { class WordBasedCompletionItemProvider implements modes.ISuggestSupport {
private readonly _workerManager: WorkerManager; private readonly _workerManager: WorkerManager;
...@@ -110,16 +89,29 @@ class WordBasedCompletionItemProvider implements modes.ISuggestSupport { ...@@ -110,16 +89,29 @@ class WordBasedCompletionItemProvider implements modes.ISuggestSupport {
provideCompletionItems(model: editorCommon.IModel, position: Position): TPromise<modes.ISuggestResult> { provideCompletionItems(model: editorCommon.IModel, position: Position): TPromise<modes.ISuggestResult> {
// TODO(joh) should we force tokenization? const { wordBasedSuggestions } = this._configurationService.getConfiguration<editorCommon.IEditorOptions>('editor');
// model.forceTokenization(position.lineNumber);
const config = WordBasedCompletionConfig.fromOldConfig(this._configurationService.lookup<boolean>('editor.wordBasedSuggestions').value); if (wordBasedSuggestions === false) {
const tokens = model.getLineTokens(position.lineNumber); // simple -> disabled everywhere
const { tokenType } = tokens.findTokenAtOffset(position.column - 1); return undefined;
if (config.accept(tokenType)) { } else if (wordBasedSuggestions === true) {
// simple -> enabled for all tokens
return this._workerManager.withWorker().then(client => client.textualSuggest(model.uri, position)); return this._workerManager.withWorker().then(client => client.textualSuggest(model.uri, position));
} else { } else {
return undefined; // check with token type and config
const tokens = model.getLineTokens(position.lineNumber);
const { tokenType } = tokens.findTokenAtOffset(position.column - 1);
const shoudSuggestHere = (tokenType === modes.StandardTokenType.Comment && wordBasedSuggestions.comments)
|| (tokenType === modes.StandardTokenType.String && wordBasedSuggestions.strings)
|| (tokenType === modes.StandardTokenType.Other && wordBasedSuggestions.default);
if (shoudSuggestHere) {
return this._workerManager.withWorker().then(client => client.textualSuggest(model.uri, position));
} else {
return undefined;
}
} }
} }
} }
......
...@@ -1397,7 +1397,11 @@ declare module monaco.editor { ...@@ -1397,7 +1397,11 @@ declare module monaco.editor {
/** /**
* Enable word based suggestions. Defaults to 'true' * Enable word based suggestions. Defaults to 'true'
*/ */
wordBasedSuggestions?: boolean; wordBasedSuggestions?: boolean | {
strings?: boolean;
comments?: boolean;
default?: boolean;
};
/** /**
* The font size for the suggest widget. * The font size for the suggest widget.
* Defaults to the editor font size. * Defaults to the editor font size.
...@@ -1619,7 +1623,11 @@ declare module monaco.editor { ...@@ -1619,7 +1623,11 @@ declare module monaco.editor {
readonly acceptSuggestionOnCommitCharacter: boolean; readonly acceptSuggestionOnCommitCharacter: boolean;
readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none'; readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
readonly emptySelectionClipboard: boolean; readonly emptySelectionClipboard: boolean;
readonly wordBasedSuggestions: boolean; readonly wordBasedSuggestions: boolean | {
strings?: boolean;
comments?: boolean;
default?: boolean;
};
readonly suggestFontSize: number; readonly suggestFontSize: number;
readonly suggestLineHeight: number; readonly suggestLineHeight: number;
readonly selectionHighlight: boolean; readonly selectionHighlight: boolean;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册