mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Use word related methods always through ITextModel
This commit is contained in:
parent
c421e6240e
commit
b99fd99594
|
@ -193,7 +193,7 @@ class WordBasedCompletionItemProvider implements languages.CompletionItemProvide
|
|||
}
|
||||
|
||||
const wordDefRegExp = this.languageConfigurationService.getLanguageConfiguration(model.getLanguageId()).getWordDefinition();
|
||||
const word = model.tokenization.getWordAtPosition(position);
|
||||
const word = model.getWordAtPosition(position);
|
||||
const replace = !word ? Range.fromPositions(position) : new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
|
||||
const insert = replace.setEndPosition(position.lineNumber, position.column);
|
||||
|
||||
|
|
|
@ -870,7 +870,6 @@ export interface ITextModel {
|
|||
*/
|
||||
getWordUntilPosition(position: IPosition): IWordAtPosition;
|
||||
|
||||
|
||||
/**
|
||||
* Change the decorations. The callback will be called with a change accessor
|
||||
* that becomes invalid as soon as the callback finishes executing.
|
||||
|
|
|
@ -163,7 +163,7 @@ export class MarkerDecorationsService extends Disposable implements IMarkerDecor
|
|||
return ret;
|
||||
}
|
||||
|
||||
const word = model.tokenization.getWordAtPosition(ret.getStartPosition());
|
||||
const word = model.getWordAtPosition(ret.getStartPosition());
|
||||
if (word) {
|
||||
ret = new Range(ret.startLineNumber, word.startColumn, ret.endLineNumber, word.endColumn);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
import { Event } from 'vs/base/common/event';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { IWordAtPosition } from 'vs/editor/common/core/wordHelper';
|
||||
import { StandardTokenType } from 'vs/editor/common/languages';
|
||||
import { ContiguousMultilineTokens } from 'vs/editor/common/tokens/contiguousMultilineTokens';
|
||||
import { LineTokens } from 'vs/editor/common/tokens/lineTokens';
|
||||
|
@ -86,20 +85,6 @@ export interface ITokenizationTextModelPart {
|
|||
*/
|
||||
tokenizeLineWithEdit(position: IPosition, length: number, newText: string): LineTokens | null;
|
||||
|
||||
/**
|
||||
* Get the word under or besides `position`.
|
||||
* @param position The position to look for a word.
|
||||
* @return The word under or besides `position`. Might be null.
|
||||
*/
|
||||
getWordAtPosition(position: IPosition): IWordAtPosition | null;
|
||||
|
||||
/**
|
||||
* Get the word under or besides `position` trimmed to `position`.column
|
||||
* @param position The position to look for a word.
|
||||
* @return The word under or besides `position`. Will never be null.
|
||||
*/
|
||||
getWordUntilPosition(position: IPosition): IWordAtPosition;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
|
|
@ -117,7 +117,7 @@ export class MarkerList {
|
|||
let range = Range.lift(this._markers[i]);
|
||||
|
||||
if (range.isEmpty()) {
|
||||
const word = model.tokenization.getWordAtPosition(range.getStartPosition());
|
||||
const word = model.getWordAtPosition(range.getStartPosition());
|
||||
if (word) {
|
||||
range = new Range(range.startLineNumber, word.startColumn, range.startLineNumber, word.endColumn);
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ export abstract class SymbolNavigationAction extends EditorAction {
|
|||
if (referenceCount === 0) {
|
||||
// no result -> show message
|
||||
if (!this.configuration.muteMessage) {
|
||||
const info = model.tokenization.getWordAtPosition(position);
|
||||
const info = model.getWordAtPosition(position);
|
||||
MessageController.get(editor)?.showMessage(this._getNoResultFoundMessage(info), position);
|
||||
}
|
||||
} else if (referenceCount === 1 && altAction) {
|
||||
|
|
|
@ -136,7 +136,7 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
this.toUnhookForKeyboard.clear();
|
||||
|
||||
// Find word at mouse position
|
||||
const word = position ? this.editor.getModel()?.tokenization.getWordAtPosition(position) : null;
|
||||
const word = position ? this.editor.getModel()?.getWordAtPosition(position) : null;
|
||||
if (!word) {
|
||||
this.currentWordAtPosition = null;
|
||||
this.removeLinkDecorations();
|
||||
|
|
|
@ -81,7 +81,7 @@ export class FilePreview implements IDisposable {
|
|||
}
|
||||
|
||||
const { startLineNumber, startColumn, endLineNumber, endColumn } = range;
|
||||
const word = model.tokenization.getWordUntilPosition({ lineNumber: startLineNumber, column: startColumn - n });
|
||||
const word = model.getWordUntilPosition({ lineNumber: startLineNumber, column: startColumn - n });
|
||||
const beforeRange = new Range(startLineNumber, word.startColumn, startLineNumber, startColumn);
|
||||
const afterRange = new Range(endLineNumber, endColumn, endLineNumber, Constants.MAX_SAFE_SMALL_INTEGER);
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ export class InlayHintsFragments {
|
|||
|
||||
private static _getRangeAtPosition(model: ITextModel, position: IPosition): Range {
|
||||
const line = position.lineNumber;
|
||||
const word = model.tokenization.getWordAtPosition(position);
|
||||
const word = model.getWordAtPosition(position);
|
||||
if (word) {
|
||||
// always prefer the word range
|
||||
return new Range(line, word.startColumn, line, word.endColumn);
|
||||
|
|
|
@ -771,7 +771,7 @@ export interface TrackedInlineCompletion extends NormalizedInlineCompletion {
|
|||
}
|
||||
|
||||
function getDefaultRange(position: Position, model: ITextModel): Range {
|
||||
const word = model.tokenization.getWordAtPosition(position);
|
||||
const word = model.getWordAtPosition(position);
|
||||
const maxColumn = model.getLineMaxColumn(position.lineNumber);
|
||||
// By default, always replace up until the end of the current line.
|
||||
// This default might be subject to change!
|
||||
|
|
|
@ -127,7 +127,7 @@ suite('Suggest Widget Model', () => {
|
|||
const provider: CompletionItemProvider = {
|
||||
triggerCharacters: ['.'],
|
||||
async provideCompletionItems(model, pos) {
|
||||
const word = model.tokenization.getWordAtPosition(pos);
|
||||
const word = model.getWordAtPosition(pos);
|
||||
const range = word
|
||||
? { startLineNumber: 1, startColumn: word.startColumn, endLineNumber: 1, endColumn: word.endColumn }
|
||||
: Range.fromPositions(pos);
|
||||
|
|
|
@ -74,7 +74,7 @@ suite('linked editing', () => {
|
|||
|
||||
disposables.add(languageFeaturesService.linkedEditingRangeProvider.register(mockFileSelector, {
|
||||
provideLinkedEditingRanges(model: ITextModel, pos: IPosition) {
|
||||
const wordAtPos = model.tokenization.getWordAtPosition(pos);
|
||||
const wordAtPos = model.getWordAtPosition(pos);
|
||||
if (wordAtPos) {
|
||||
const matches = model.findMatches(wordAtPos.word, false, false, true, USUAL_WORD_SEPARATORS, false);
|
||||
return { ranges: matches.map(m => m.range), wordPattern: initialState.responseWordPattern };
|
||||
|
|
|
@ -74,7 +74,7 @@ class RenameSkeleton {
|
|||
return res;
|
||||
}
|
||||
|
||||
const word = this.model.tokenization.getWordAtPosition(this.position);
|
||||
const word = this.model.getWordAtPosition(this.position);
|
||||
if (!word) {
|
||||
return {
|
||||
range: Range.fromPositions(this.position),
|
||||
|
|
|
@ -26,7 +26,7 @@ export class WordSelectionRangeProvider implements SelectionRangeProvider {
|
|||
}
|
||||
|
||||
private _addInWordRanges(bucket: SelectionRange[], model: ITextModel, pos: Position): void {
|
||||
const obj = model.tokenization.getWordAtPosition(pos);
|
||||
const obj = model.getWordAtPosition(pos);
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ export class WordSelectionRangeProvider implements SelectionRangeProvider {
|
|||
}
|
||||
|
||||
private _addWordRanges(bucket: SelectionRange[], model: ITextModel, pos: Position): void {
|
||||
const word = model.tokenization.getWordAtPosition(pos);
|
||||
const word = model.getWordAtPosition(pos);
|
||||
if (word) {
|
||||
bucket.push({ range: new Range(pos.lineNumber, word.startColumn, pos.lineNumber, word.endColumn) });
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ export class SnippetController2 implements IEditorContribution {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const info = model.tokenization.getWordUntilPosition(position);
|
||||
const info = model.getWordUntilPosition(position);
|
||||
const isAnyOfOptions = Boolean(activeChoice.options.find(o => o.value === info.word));
|
||||
const suggestions: CompletionItem[] = [];
|
||||
for (let i = 0; i < activeChoice.options.length; i++) {
|
||||
|
|
|
@ -131,7 +131,7 @@ export class SelectionBasedVariableResolver implements VariableResolver {
|
|||
return this._model.getLineContent(this._selection.positionLineNumber);
|
||||
|
||||
} else if (name === 'TM_CURRENT_WORD') {
|
||||
const info = this._model.tokenization.getWordAtPosition({
|
||||
const info = this._model.getWordAtPosition({
|
||||
lineNumber: this._selection.positionLineNumber,
|
||||
column: this._selection.positionColumn
|
||||
});
|
||||
|
|
|
@ -207,7 +207,7 @@ export async function provideSuggestionItems(
|
|||
const sw = new StopWatch(true);
|
||||
position = position.clone();
|
||||
|
||||
const word = model.tokenization.getWordAtPosition(position);
|
||||
const word = model.getWordAtPosition(position);
|
||||
const defaultReplaceRange = word ? new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn) : Range.fromPositions(position);
|
||||
const defaultRange = { replace: defaultReplaceRange, insert: defaultReplaceRange.setEndPosition(position.lineNumber, position.column) };
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class SuggestInlineCompletions implements InlineCompletionsProvider<InlineComple
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const wordInfo = model.tokenization.getWordAtPosition(position);
|
||||
const wordInfo = model.getWordAtPosition(position);
|
||||
if (!wordInfo || wordInfo.word.length === 0 || wordInfo.endColumn !== position.column) {
|
||||
// not without true prefix, not inside word
|
||||
return;
|
||||
|
|
|
@ -156,7 +156,7 @@ export class PrefixMemory extends Memory {
|
|||
private _seq = 0;
|
||||
|
||||
memorize(model: ITextModel, pos: IPosition, item: CompletionItem): void {
|
||||
const { word } = model.tokenization.getWordUntilPosition(pos);
|
||||
const { word } = model.getWordUntilPosition(pos);
|
||||
const key = `${model.getLanguageId()}/${word}`;
|
||||
this._trie.set(key, {
|
||||
type: item.completion.kind,
|
||||
|
@ -166,7 +166,7 @@ export class PrefixMemory extends Memory {
|
|||
}
|
||||
|
||||
override select(model: ITextModel, pos: IPosition, items: CompletionItem[]): number {
|
||||
let { word } = model.tokenization.getWordUntilPosition(pos);
|
||||
let { word } = model.getWordUntilPosition(pos);
|
||||
if (!word) {
|
||||
return super.select(model, pos, items);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ export class LineContext {
|
|||
const pos = editor.getPosition();
|
||||
model.tokenization.tokenizeIfCheap(pos.lineNumber);
|
||||
|
||||
const word = model.tokenization.getWordAtPosition(pos);
|
||||
const word = model.getWordAtPosition(pos);
|
||||
if (!word) {
|
||||
return false;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ export class LineContext {
|
|||
|
||||
constructor(model: ITextModel, position: Position, auto: boolean, shy: boolean) {
|
||||
this.leadingLineContent = model.getLineContent(position.lineNumber).substr(0, position.column - 1);
|
||||
this.leadingWord = model.tokenization.getWordUntilPosition(position);
|
||||
this.leadingWord = model.getWordUntilPosition(position);
|
||||
this.lineNumber = position.lineNumber;
|
||||
this.column = position.column;
|
||||
this.auto = auto;
|
||||
|
|
|
@ -50,7 +50,7 @@ export class WordContextKey {
|
|||
}
|
||||
const model = this._editor.getModel();
|
||||
const selection = this._editor.getSelection();
|
||||
const word = model.tokenization.getWordAtPosition(selection.getStartPosition());
|
||||
const word = model.getWordAtPosition(selection.getStartPosition());
|
||||
if (!word) {
|
||||
this._ckAtEnd.set(false);
|
||||
return;
|
||||
|
|
|
@ -46,7 +46,7 @@ export abstract class WordDistance {
|
|||
}
|
||||
|
||||
// remove current word
|
||||
const wordUntilPos = model.tokenization.getWordUntilPosition(position);
|
||||
const wordUntilPos = model.getWordUntilPosition(position);
|
||||
delete wordRanges[wordUntilPos.word];
|
||||
|
||||
return new class extends WordDistance {
|
||||
|
|
|
@ -164,7 +164,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
|||
|
||||
|
||||
function getDefaultSuggestRange(model: ITextModel, position: Position) {
|
||||
const wordUntil = model.tokenization.getWordUntilPosition(position);
|
||||
const wordUntil = model.getWordUntilPosition(position);
|
||||
return new Range(position.lineNumber, wordUntil.startColumn, position.lineNumber, wordUntil.endColumn);
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
|||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{
|
||||
label: doc.tokenization.getWordUntilPosition(pos).word,
|
||||
label: doc.getWordUntilPosition(pos).word,
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'foofoo',
|
||||
range: getDefaultSuggestRange(doc, pos)
|
||||
|
@ -824,7 +824,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
|||
disposables.add(registry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos) {
|
||||
countB += 1;
|
||||
if (!doc.tokenization.getWordUntilPosition(pos).word.startsWith('a')) {
|
||||
if (!doc.getWordUntilPosition(pos).word.startsWith('a')) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
|
|
|
@ -81,7 +81,7 @@ abstract class OccurenceAtPositionRequest implements IOccurenceAtPositionRequest
|
|||
protected abstract _compute(model: ITextModel, selection: Selection, wordSeparators: string, token: CancellationToken): Promise<DocumentHighlight[]>;
|
||||
|
||||
private _getCurrentWordRange(model: ITextModel, selection: Selection): Range | null {
|
||||
const word = model.tokenization.getWordAtPosition(selection.getPosition());
|
||||
const word = model.getWordAtPosition(selection.getPosition());
|
||||
if (word) {
|
||||
return new Range(selection.startLineNumber, word.startColumn, selection.startLineNumber, word.endColumn);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ class TextualOccurenceAtPositionRequest extends OccurenceAtPositionRequest {
|
|||
return [];
|
||||
}
|
||||
|
||||
const word = model.tokenization.getWordAtPosition(selection.getPosition());
|
||||
const word = model.getWordAtPosition(selection.getPosition());
|
||||
|
||||
if (!word || word.word.length > 1000) {
|
||||
return [];
|
||||
|
@ -353,7 +353,7 @@ class WordHighlighter {
|
|||
let lineNumber = editorSelection.startLineNumber;
|
||||
let startColumn = editorSelection.startColumn;
|
||||
|
||||
return this.model.tokenization.getWordAtPosition({
|
||||
return this.model.getWordAtPosition({
|
||||
lineNumber: lineNumber,
|
||||
column: startColumn
|
||||
});
|
||||
|
|
|
@ -442,7 +442,7 @@ export function registerHoverProvider(languageSelector: LanguageSelector, provid
|
|||
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
|
||||
return languageFeaturesService.hoverProvider.register(languageSelector, {
|
||||
provideHover: (model: model.ITextModel, position: Position, token: CancellationToken): Promise<languages.Hover | undefined> => {
|
||||
const word = model.tokenization.getWordAtPosition(position);
|
||||
const word = model.getWordAtPosition(position);
|
||||
|
||||
return Promise.resolve<languages.Hover | null | undefined>(provider.provideHover(model, position, token)).then((value): languages.Hover | undefined => {
|
||||
if (!value) {
|
||||
|
|
|
@ -442,17 +442,17 @@ suite('Editor Model - Words', () => {
|
|||
const thisModel = createTextModel(text.join('\n'));
|
||||
disposables.push(thisModel);
|
||||
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 1)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 2)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 4)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 5)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 6)), { word: 'text', startColumn: 6, endColumn: 10 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 19)), { word: 'some', startColumn: 15, endColumn: 19 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 20)), null);
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 21)), { word: 'words', startColumn: 21, endColumn: 26 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 26)), { word: 'words', startColumn: 21, endColumn: 26 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 27)), null);
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 28)), null);
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 1)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 2)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 4)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 5)), { word: 'This', startColumn: 1, endColumn: 5 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 6)), { word: 'text', startColumn: 6, endColumn: 10 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 19)), { word: 'some', startColumn: 15, endColumn: 19 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 20)), null);
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 21)), { word: 'words', startColumn: 21, endColumn: 26 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 26)), { word: 'words', startColumn: 21, endColumn: 26 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 27)), null);
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 28)), null);
|
||||
});
|
||||
|
||||
test('getWordAtPosition at embedded language boundaries', () => {
|
||||
|
@ -463,13 +463,13 @@ suite('Editor Model - Words', () => {
|
|||
|
||||
const model = disposables.add(instantiateTextModel(instantiationService, 'ab<xx>ab<x>', outerMode.languageId));
|
||||
|
||||
assert.deepStrictEqual(model.tokenization.getWordAtPosition(new Position(1, 1)), { word: 'ab', startColumn: 1, endColumn: 3 });
|
||||
assert.deepStrictEqual(model.tokenization.getWordAtPosition(new Position(1, 2)), { word: 'ab', startColumn: 1, endColumn: 3 });
|
||||
assert.deepStrictEqual(model.tokenization.getWordAtPosition(new Position(1, 3)), { word: 'ab', startColumn: 1, endColumn: 3 });
|
||||
assert.deepStrictEqual(model.tokenization.getWordAtPosition(new Position(1, 4)), { word: 'xx', startColumn: 4, endColumn: 6 });
|
||||
assert.deepStrictEqual(model.tokenization.getWordAtPosition(new Position(1, 5)), { word: 'xx', startColumn: 4, endColumn: 6 });
|
||||
assert.deepStrictEqual(model.tokenization.getWordAtPosition(new Position(1, 6)), { word: 'xx', startColumn: 4, endColumn: 6 });
|
||||
assert.deepStrictEqual(model.tokenization.getWordAtPosition(new Position(1, 7)), { word: 'ab', startColumn: 7, endColumn: 9 });
|
||||
assert.deepStrictEqual(model.getWordAtPosition(new Position(1, 1)), { word: 'ab', startColumn: 1, endColumn: 3 });
|
||||
assert.deepStrictEqual(model.getWordAtPosition(new Position(1, 2)), { word: 'ab', startColumn: 1, endColumn: 3 });
|
||||
assert.deepStrictEqual(model.getWordAtPosition(new Position(1, 3)), { word: 'ab', startColumn: 1, endColumn: 3 });
|
||||
assert.deepStrictEqual(model.getWordAtPosition(new Position(1, 4)), { word: 'xx', startColumn: 4, endColumn: 6 });
|
||||
assert.deepStrictEqual(model.getWordAtPosition(new Position(1, 5)), { word: 'xx', startColumn: 4, endColumn: 6 });
|
||||
assert.deepStrictEqual(model.getWordAtPosition(new Position(1, 6)), { word: 'xx', startColumn: 4, endColumn: 6 });
|
||||
assert.deepStrictEqual(model.getWordAtPosition(new Position(1, 7)), { word: 'ab', startColumn: 7, endColumn: 9 });
|
||||
|
||||
disposables.dispose();
|
||||
});
|
||||
|
@ -488,14 +488,14 @@ suite('Editor Model - Words', () => {
|
|||
|
||||
const thisModel = disposables.add(instantiateTextModel(instantiationService, '.🐷-a-b', MODE_ID));
|
||||
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 1)), { word: '.', startColumn: 1, endColumn: 2 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 2)), { word: '.', startColumn: 1, endColumn: 2 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 3)), null);
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 4)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 5)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 6)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 7)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.tokenization.getWordAtPosition(new Position(1, 8)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 1)), { word: '.', startColumn: 1, endColumn: 2 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 2)), { word: '.', startColumn: 1, endColumn: 2 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 3)), null);
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 4)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 5)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 6)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 7)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
assert.deepStrictEqual(thisModel.getWordAtPosition(new Position(1, 8)), { word: '-a-b', startColumn: 4, endColumn: 8 });
|
||||
|
||||
disposables.dispose();
|
||||
});
|
||||
|
|
12
src/vs/monaco.d.ts
vendored
12
src/vs/monaco.d.ts
vendored
|
@ -1400,18 +1400,6 @@ declare namespace monaco.editor {
|
|||
* Provides tokenization related functionality of the text model.
|
||||
*/
|
||||
export interface ITokenizationTextModelPart {
|
||||
/**
|
||||
* Get the word under or besides `position`.
|
||||
* @param position The position to look for a word.
|
||||
* @return The word under or besides `position`. Might be null.
|
||||
*/
|
||||
getWordAtPosition(position: IPosition): IWordAtPosition | null;
|
||||
/**
|
||||
* Get the word under or besides `position` trimmed to `position`.column
|
||||
* @param position The position to look for a word.
|
||||
* @return The word under or besides `position`. Will never be null.
|
||||
*/
|
||||
getWordUntilPosition(position: IPosition): IWordAtPosition;
|
||||
getLanguageId(): string;
|
||||
getLanguageIdAtPosition(lineNumber: number, column: number): string;
|
||||
setLanguageId(languageId: string): void;
|
||||
|
|
|
@ -313,7 +313,7 @@ class ShowDebugHoverAction extends EditorAction {
|
|||
if (!position || !editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
const word = editor.getModel().tokenization.getWordAtPosition(position);
|
||||
const word = editor.getModel().getWordAtPosition(position);
|
||||
if (!word) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
|
|||
|
||||
const model = this.replInput.getModel();
|
||||
if (model) {
|
||||
const word = model.tokenization.getWordAtPosition(position);
|
||||
const word = model.getWordAtPosition(position);
|
||||
const overwriteBefore = word ? word.word.length : 0;
|
||||
const text = model.getValue();
|
||||
const focusedStackFrame = this.debugService.getViewModel().focusedStackFrame;
|
||||
|
|
|
@ -26,7 +26,7 @@ export class ExtensionsCompletionItemsProvider extends Disposable implements IWo
|
|||
this._register(languageFeaturesService.completionProvider.register({ language: 'jsonc', pattern: '**/settings.json' }, {
|
||||
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, token: CancellationToken): Promise<CompletionList> => {
|
||||
const getWordRangeAtPosition = (model: ITextModel, position: Position): Range | null => {
|
||||
const wordAtPosition = model.tokenization.getWordAtPosition(position);
|
||||
const wordAtPosition = model.getWordAtPosition(position);
|
||||
return wordAtPosition ? new Range(position.lineNumber, wordAtPosition.startColumn, position.lineNumber, wordAtPosition.endColumn) : null;
|
||||
};
|
||||
|
||||
|
|
|
@ -1160,7 +1160,7 @@ export class SearchView extends ViewPane {
|
|||
}
|
||||
|
||||
if (range.isEmpty() && this.searchConfig.seedWithNearestWord && allowUnselectedWord) {
|
||||
const wordAtPosition = editor.getModel().tokenization.getWordAtPosition(range.getStartPosition());
|
||||
const wordAtPosition = editor.getModel().getWordAtPosition(range.getStartPosition());
|
||||
if (wordAtPosition) {
|
||||
return wordAtPosition.word;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ export const openNewSearchEditor =
|
|||
selected = (selection && activeModel?.getModel()?.getValueInRange(selection)) ?? '';
|
||||
|
||||
if (selection?.isEmpty() && configurationService.getValue<ISearchConfigurationProperties>('search').seedWithNearestWord) {
|
||||
const wordAtPosition = activeModel.getModel()?.tokenization.getWordAtPosition(selection.getStartPosition());
|
||||
const wordAtPosition = activeModel.getModel()?.getWordAtPosition(selection.getStartPosition());
|
||||
if (wordAtPosition) {
|
||||
selected = wordAtPosition.word;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ export class SnippetCompletionProvider implements CompletionItemProvider {
|
|||
const snippets = new Set(await this._snippets.getSnippets(languageId));
|
||||
|
||||
const lineContentLow = model.getLineContent(position.lineNumber).toLowerCase();
|
||||
const wordUntil = model.tokenization.getWordUntilPosition(position).word.toLowerCase();
|
||||
const wordUntil = model.getWordUntilPosition(position).word.toLowerCase();
|
||||
|
||||
const suggestions: SnippetCompletion[] = [];
|
||||
const columnOffset = position.column - 1;
|
||||
|
|
Loading…
Reference in a new issue