@@ -8,6 +8,9 @@ import { IModeService } from 'vs/editor/common/services/modeService';
88import { IModelService } from 'vs/editor/common/services/modelService' ;
99import { MainThreadLanguagesShape , MainContext , IExtHostContext } from '../common/extHost.protocol' ;
1010import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers' ;
11+ import { IPosition } from 'vs/editor/common/core/position' ;
12+ import { IRange , Range } from 'vs/editor/common/core/range' ;
13+ import { StandardTokenType } from 'vs/editor/common/modes' ;
1114
1215@extHostNamedCustomer ( MainContext . MainThreadLanguages )
1316export class MainThreadLanguages implements MainThreadLanguagesShape {
@@ -40,4 +43,19 @@ export class MainThreadLanguages implements MainThreadLanguagesShape {
4043 this . _modelService . setMode ( model , this . _modeService . create ( languageId ) ) ;
4144 return Promise . resolve ( undefined ) ;
4245 }
46+
47+ async $tokensAtPosition ( resource : UriComponents , position : IPosition ) : Promise < undefined | { type : StandardTokenType , range : IRange } > {
48+ const uri = URI . revive ( resource ) ;
49+ const model = this . _modelService . getModel ( uri ) ;
50+ if ( ! model ) {
51+ return undefined ;
52+ }
53+ model . tokenizeIfCheap ( position . lineNumber ) ;
54+ const tokens = model . getLineTokens ( position . lineNumber ) ;
55+ const idx = tokens . findTokenIndexAtOffset ( position . column - 1 ) ;
56+ return {
57+ type : tokens . getStandardTokenType ( idx ) ,
58+ range : new Range ( position . lineNumber , 1 + tokens . getStartOffset ( idx ) , position . lineNumber , 1 + tokens . getEndOffset ( idx ) )
59+ } ;
60+ }
4361}
0 commit comments