Skip to content

Commit 2475fd2

Browse files
committed
Adapt to sourcelib methods
1 parent 5340c86 commit 2475fd2

8 files changed

Lines changed: 17 additions & 25 deletions

File tree

src/compiler/compiler-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import vscode from "vscode";
2-
import { isWhitespace } from "@sourcelib/kv";
2+
import { isWhitespace } from "@sourcelib/kv/";
33
import * as main from "../main";
44
import * as fs from "fs";
55
import { execFile } from "child_process";

src/language/KvDocument.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22
import { KvPair, KvPiece } from "../Kv";
3-
import { Tokenizer, TokenList, Token, TokenType } from "@sourcelib/kv";
3+
import { tokenize, TokenList, Token, TokenType } from "@sourcelib/kv";
44
import { KvTokensProviderBase } from "./KvTokensProviderBase";
55

66
export 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 {

src/language/KvFormatter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
// TODO: Disabled until new formatter is implemented in sourcelib
2+
3+
/*
14
import vscode from "vscode";
2-
import { FormattingOptions, formatAll } from "@sourcelib/kv";
5+
import { } from "@sourcelib/kv";
36
import KvDocument from "./KvDocument";
47
import * as main from "../main";
58
69
export class KvDocumentFormatter implements vscode.DocumentFormattingEditProvider {
7-
810
protected createFormattingOptions(): FormattingOptions {
911
return {
1012
braceOnNewline: main.config.get("keyvalueBracesOnNewline"),
1113
alwaysQuote: main.config.get("keyvalueAlwaysQuote")
1214
} as FormattingOptions;
1315
}
14-
1516
provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): vscode.TextEdit[] {
16-
17+
1718
const tokens = KvDocument.tokenize(document);
1819
if (tokens == null)
1920
return [];
@@ -32,3 +33,5 @@ export class KvDocumentFormatter implements vscode.DocumentFormattingEditProvide
3233
}
3334
3435
}
36+
37+
*/

src/language/KvTokensProviderBase.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ export abstract class KvTokensProviderBase implements vscode.DocumentSemanticTok
7878
continue;
7979
}
8080

81-
// We're a keyvalue's key. Process the value too and skip forward
8281
if (token.type === TokenType.Value) {
83-
8482
this.processKvValue(token, tokenRange, tokensBuilder, kvDoc, currentScope);
85-
8683
continue;
8784
}
8885

src/language/LangCaptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import vscode from "vscode";
77
import KvDocument from "./KvDocument";
8-
import { KvDocumentFormatter } from "./KvFormatter";
8+
//import { KvDocumentFormatter } from "./KvFormatter";
99
import { CaptionsColorsProvider } from "./CaptionsColorsProvider";
1010
import { CaptionsSemanticTokenProvider } from "./CaptionsSemanticTokenProvider";
1111

src/language/LangKv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as vscode from "vscode";
99
import { KvTokensProviderBase } from "./KvTokensProviderBase";
10-
import { KvDocumentFormatter } from "./KvFormatter";
10+
//import { KvDocumentFormatter } from "./KvFormatter";
1111
import { KvSemanticProcessor, KvSemanticProcessorParams } from "./KvSemanticProcessor";
1212
import KvDocument from "./KvDocument";
1313
import { matrixRegExp } from "@sourcelib/vmt";

src/language/LangVmt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import vscode from "vscode";
77
import KvDocument from "./KvDocument";
8-
import { KvDocumentFormatter } from "./KvFormatter";
8+
//import { KvDocumentFormatter } from "./KvFormatter";
99
import { ShaderParam } from "@sourcelib/vmt";
1010
import * as main from "../main";
1111
import { ShaderParamCompletionItemProvider } from "./ShaderParamCompletionItemProvider";

src/language/ShaderParamColorsProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ShaderParamColorsProvider implements vscode.DocumentColorProvider {
1717
// TODO: This seems like it should be reusable.
1818
const valueTokens = kvDoc.tokens.getAllOfType(TokenType.Value);
1919
valueTokens.forEach(t => {
20-
const line = document.positionAt(t.range.start).line;
20+
const line = document.positionAt(t.range.getStart()).line;
2121
const kv = kvDoc.getKeyValueAt(line);
2222
if (kv == null)
2323
return;

0 commit comments

Comments
 (0)