11import * as vscode from "vscode" ;
2+ import * as sourcelib from "sourcelib" ;
23import { KvPiece } from "../Kv" ;
3- import { isQuoted , stripQuotes , Token , TokenList , TokenType } from "@sourcelib/kv" ;
44import KvDocument from "./KvDocument" ;
55import { KvSemanticProcessor , KvSemanticProcessorParams } from "./KvSemanticProcessor" ;
66
@@ -18,14 +18,14 @@ export abstract class KvTokensProviderBase implements vscode.DocumentSemanticTok
1818 diagnostics : vscode . Diagnostic [ ] = [ ] ;
1919 bracketStack = 0 ;
2020
21- protected tokens : TokenList ;
21+ protected tokens : sourcelib . kv . TokenList ;
2222
2323 protected abstract valueProcessors : KvSemanticProcessor [ ] ;
2424
2525 protected abstract keyProcessors : KvSemanticProcessor [ ] ;
2626
2727 constructor ( legend : vscode . SemanticTokensLegend , diagnosticCollection : vscode . DiagnosticCollection ) {
28- this . tokens = new TokenList ;
28+ this . tokens = new sourcelib . kv . TokenList ;
2929 this . legend = legend ;
3030 this . diagnosticCollection = diagnosticCollection ;
3131 }
@@ -51,50 +51,50 @@ export abstract class KvTokensProviderBase implements vscode.DocumentSemanticTok
5151 const tokenRange = kvDoc . getTokenRange ( token ) ;
5252
5353 // No further processing on comments
54- if ( token . type === TokenType . Comment ) {
54+ if ( token . type === sourcelib . kv . TokenType . Comment ) {
5555 tokensBuilder . push ( tokenRange , "comment" , [ ] ) ;
5656 continue ;
5757 }
5858
59- if ( token . type === TokenType . Key ) {
59+ if ( token . type === sourcelib . kv . TokenType . Key ) {
6060
6161 // Get next token that isn't a comment
6262 const interestingToken = this . getNextInterestingToken ( kvDoc . tokens , i ) ;
6363
6464 // We're an object key
65- if ( interestingToken ?. token . type === TokenType . ObjectStart ) {
65+ if ( interestingToken ?. token . type === sourcelib . kv . TokenType . ObjectStart ) {
6666 tokensBuilder . push ( tokenRange , "struct" , [ ] ) ;
6767 this . bracketStack ++ ;
68- currentScope += "." + stripQuotes ( token . value . toLowerCase ( ) ) ;
68+ currentScope += "." + sourcelib . kv . stripQuotes ( token . value . toLowerCase ( ) ) ;
6969 continue ;
7070 }
7171
7272 this . processKvKey ( token , tokenRange , tokensBuilder , kvDoc , currentScope ) ;
7373
7474 // Is this key not followed by a value?
7575 const interestingTokenType = interestingToken ?. token . type ;
76- if ( interestingTokenType !== TokenType . Value && interestingTokenType !== TokenType . Conditional ) {
76+ if ( interestingTokenType !== sourcelib . kv . TokenType . Value && interestingTokenType !== sourcelib . kv . TokenType . Conditional ) {
7777 this . diagnostics . push ( new vscode . Diagnostic ( tokenRange , "Expecting value to this key" , vscode . DiagnosticSeverity . Error ) ) ;
7878 }
7979 continue ;
8080 }
8181
82- if ( token . type === TokenType . Value ) {
82+ if ( token . type === sourcelib . kv . TokenType . Value ) {
8383 this . processKvValue ( token , tokenRange , tokensBuilder , kvDoc , currentScope ) ;
8484 continue ;
8585 }
8686
87- if ( token . type === TokenType . ObjectEnd ) {
87+ if ( token . type === sourcelib . kv . TokenType . ObjectEnd ) {
8888 this . bracketStack -- ;
8989 currentScope = currentScope . substring ( 0 , currentScope . lastIndexOf ( "." ) ) ;
9090 continue ;
9191 }
9292
93- if ( token . type === TokenType . PreprocessorKey ) {
93+ if ( token . type === sourcelib . kv . TokenType . PreprocessorKey ) {
9494
9595 // Get next token that isn't a comment
9696 const interestingToken = this . getNextInterestingToken ( kvDoc . tokens , i ) ;
97- if ( interestingToken ?. token . type === TokenType . Value ) {
97+ if ( interestingToken ?. token . type === sourcelib . kv . TokenType . Value ) {
9898
9999 const nextTokenRange = kvDoc . getTokenRange ( token ) ;
100100
@@ -108,7 +108,7 @@ export abstract class KvTokensProviderBase implements vscode.DocumentSemanticTok
108108 continue ;
109109 }
110110
111- if ( token . type === TokenType . Conditional ) {
111+ if ( token . type === sourcelib . kv . TokenType . Conditional ) {
112112 tokensBuilder . push ( tokenRange , "keyword" , [ ] ) ;
113113 }
114114 }
@@ -123,13 +123,13 @@ export abstract class KvTokensProviderBase implements vscode.DocumentSemanticTok
123123 return tokensBuilder . build ( ) ;
124124 }
125125
126- getNextInterestingToken ( tokens : TokenList , i : number ) : { token : Token ; offset : number ; } | null {
126+ getNextInterestingToken ( tokens : sourcelib . kv . TokenList , i : number ) : { token : sourcelib . kv . Token ; offset : number ; } | null {
127127 let n = 1 ;
128128 if ( tokens . length - 1 < i + n ) {
129129 return null ;
130130 }
131131 let nextToken = tokens [ i + n ] ;
132- while ( nextToken . type === TokenType . Comment ) {
132+ while ( nextToken . type === sourcelib . kv . TokenType . Comment ) {
133133 nextToken = tokens [ i + n ++ ] ;
134134 if ( nextToken == null )
135135 break ;
@@ -138,18 +138,18 @@ export abstract class KvTokensProviderBase implements vscode.DocumentSemanticTok
138138 return { token : nextToken , offset : n } ;
139139 }
140140
141- protected processKvKey ( token : Token , range : vscode . Range , tokensBuilder : vscode . SemanticTokensBuilder , kvDocument : KvDocument , scope : string ) : void {
141+ protected processKvKey ( token : sourcelib . kv . Token , range : vscode . Range , tokensBuilder : vscode . SemanticTokensBuilder , kvDocument : KvDocument , scope : string ) : void {
142142 const processed = this . processString ( token , range , tokensBuilder , this . keyProcessors , kvDocument , scope ) ;
143143 if ( ! processed )
144144 tokensBuilder . push ( range , "variable" , [ "declaration" ] ) ;
145145 }
146- protected processKvValue ( token : Token , range : vscode . Range , tokensBuilder : vscode . SemanticTokensBuilder , kvDocument : KvDocument , scope : string ) : void {
146+ protected processKvValue ( token : sourcelib . kv . Token , range : vscode . Range , tokensBuilder : vscode . SemanticTokensBuilder , kvDocument : KvDocument , scope : string ) : void {
147147 const processed = this . processString ( token , range , tokensBuilder , this . valueProcessors , kvDocument , scope ) ;
148148 if ( ! processed )
149149 tokensBuilder . push ( range , "string" , [ ] ) ;
150150 }
151151
152- processString ( token : Token , range : vscode . Range , tokensBuilder : vscode . SemanticTokensBuilder , processors : KvSemanticProcessor [ ] , kvDocument : KvDocument , scope : string ) : boolean {
152+ processString ( token : sourcelib . kv . Token , range : vscode . Range , tokensBuilder : vscode . SemanticTokensBuilder , processors : KvSemanticProcessor [ ] , kvDocument : KvDocument , scope : string ) : boolean {
153153 const unquoted = KvTokensProviderBase . unquoteToken ( token , range ) ;
154154
155155 const processed = processors . some ( processor => {
@@ -170,15 +170,15 @@ export abstract class KvTokensProviderBase implements vscode.DocumentSemanticTok
170170 return processed ;
171171 }
172172
173- protected disallowDuplicate ( scopedKey : string , depth : number , token : Token ) : boolean {
173+ protected disallowDuplicate ( scopedKey : string , depth : number , token : sourcelib . kv . Token ) : boolean {
174174 return false ; // Duplicate keys are allowed by default.
175175 }
176176
177- public static unquoteToken ( token : Token , range : vscode . Range ) : KvPiece {
177+ public static unquoteToken ( token : sourcelib . kv . Token , range : vscode . Range ) : KvPiece {
178178 // Quote tokens
179179 let unquotedContent : string = token . value ;
180180 let unquotedRange : vscode . Range = range ;
181- if ( isQuoted ( token . value ) ) {
181+ if ( sourcelib . kv . isQuoted ( token . value ) ) {
182182 unquotedContent = token . value . substring ( 1 , token . value . length - 1 ) ;
183183 unquotedRange = new vscode . Range ( range . start . translate ( 0 , 1 ) , range . end . translate ( 0 , - 1 ) ) ;
184184 }
0 commit comments