mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-14 03:58:33 -05:00
Merge from vscode 79a1f5a5ca0c6c53db617aa1fa5a2396d2caebe2
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
import { MainContext, MainThreadLanguagesShape, IMainContext } from './extHost.protocol';
|
||||
import type * as vscode from 'vscode';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
|
||||
import * as typeConvert from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import { StandardTokenType, Range, Position } from 'vs/workbench/api/common/extHostTypes';
|
||||
|
||||
export class ExtHostLanguages {
|
||||
|
||||
@@ -32,4 +34,31 @@ export class ExtHostLanguages {
|
||||
}
|
||||
return data.document;
|
||||
}
|
||||
|
||||
async tokenAtPosition(document: vscode.TextDocument, position: vscode.Position): Promise<vscode.TokenInformation> {
|
||||
const versionNow = document.version;
|
||||
const pos = typeConvert.Position.from(position);
|
||||
const info = await this._proxy.$tokensAtPosition(document.uri, pos);
|
||||
const defaultRange = {
|
||||
type: StandardTokenType.Other,
|
||||
range: document.getWordRangeAtPosition(position) ?? new Range(position.line, position.character, position.line, position.character)
|
||||
};
|
||||
if (!info) {
|
||||
// no result
|
||||
return defaultRange;
|
||||
}
|
||||
const result = {
|
||||
range: typeConvert.Range.to(info.range),
|
||||
type: typeConvert.TokenType.to(info.type)
|
||||
};
|
||||
if (!result.range.contains(<Position>position)) {
|
||||
// bogous result
|
||||
return defaultRange;
|
||||
}
|
||||
if (versionNow !== document.version) {
|
||||
// concurrent change
|
||||
return defaultRange;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user