11import * as vscode from "vscode" ;
22import { KvPair , KvPiece } from "../Kv" ;
3- import { Tokenizer , TokenList , Token , TokenType } from "@sourcelib/kv" ;
3+ import { tokenize , TokenList , Token , TokenType } from "@sourcelib/kv" ;
44import { KvTokensProviderBase } from "./KvTokensProviderBase" ;
55
66export default class KvDocument {
@@ -16,18 +16,8 @@ export default class KvDocument {
1616 return this . _tokens ;
1717 }
1818
19- private static tokenizer : Tokenizer = new Tokenizer ( ) ;
20-
21- public static tokenize ( document : vscode . TextDocument ) : TokenList {
22- const text = document . getText ( ) ;
23- this . tokenizer . tokenizeFile ( text ) ;
24- const tokens = this . tokenizer . tokens ;
25-
26- return tokens ;
27- }
28-
2919 public static from ( document : vscode . TextDocument ) : KvDocument {
30- return new KvDocument ( document , this . tokenize ( document ) ) ;
20+ return new KvDocument ( document , tokenize ( document . getText ( ) ) ) ;
3121 }
3222
3323 public static tokenLegend = new vscode . SemanticTokensLegend ( [
@@ -80,7 +70,9 @@ export default class KvDocument {
8070 }
8171
8272 public getTokenRange ( token : Token ) : vscode . Range {
83- return new vscode . Range ( this . document . positionAt ( token . range . start ) , this . document . positionAt ( token . range . end ) ) ;
73+ const start = new vscode . Position ( token . line , token . range . getStart ( ) ) ;
74+ const end = new vscode . Position ( token . line , token . range . getEnd ( ) ) ;
75+ return new vscode . Range ( start , end ) ;
8476 }
8577
8678 private getUnquotedToken ( token : Token ) : KvPiece {
0 commit comments