diff --git a/extensions/typescript-language-features/src/features/semanticColoring.ts b/extensions/typescript-language-features/src/features/semanticColoring.ts index 71da3a8bb51..be83ef883c3 100644 --- a/extensions/typescript-language-features/src/features/semanticColoring.ts +++ b/extensions/typescript-language-features/src/features/semanticColoring.ts @@ -102,7 +102,6 @@ class SemanticColoringProvider implements vscode.SemanticColoringProvider { } } - console.log(result); return new vscode.SemanticColoring([new vscode.SemanticColoringArea(0, new Uint32Array(result))]); } diff --git a/src/vs/editor/common/model.ts b/src/vs/editor/common/model.ts index 7bbbae990da..0c6a851ec53 100644 --- a/src/vs/editor/common/model.ts +++ b/src/vs/editor/common/model.ts @@ -795,7 +795,7 @@ export interface ITextModel { /** * @internal */ - setSemanticTokens(tokens: MultilineTokens2[]): void; + setSemanticTokens(tokens: MultilineTokens2[] | null): void; /** * Flush all tokenization state. diff --git a/src/vs/editor/common/model/textModel.ts b/src/vs/editor/common/model/textModel.ts index 69e57f63c3e..7d13c3aa841 100644 --- a/src/vs/editor/common/model/textModel.ts +++ b/src/vs/editor/common/model/textModel.ts @@ -1721,7 +1721,7 @@ export class TextModel extends Disposable implements model.ITextModel { }); } - public setSemanticTokens(tokens: MultilineTokens2[]): void { + public setSemanticTokens(tokens: MultilineTokens2[] | null): void { this._tokens2.set(tokens); // TODO@semantic: could we reduce the event here? diff --git a/src/vs/editor/common/model/tokensStore.ts b/src/vs/editor/common/model/tokensStore.ts index 1e8ce4630c7..4f5cfb89416 100644 --- a/src/vs/editor/common/model/tokensStore.ts +++ b/src/vs/editor/common/model/tokensStore.ts @@ -752,8 +752,8 @@ export class TokensStore2 { this._pieces = []; } - public set(pieces: MultilineTokens2[]) { - this._pieces = pieces; + public set(pieces: MultilineTokens2[] | null) { + this._pieces = pieces || []; } public addSemanticTokens(lineNumber: number, aTokens: LineTokens): LineTokens { diff --git a/src/vs/editor/common/services/modelServiceImpl.ts b/src/vs/editor/common/services/modelServiceImpl.ts index 0081d95fbaa..b771a1bd85e 100644 --- a/src/vs/editor/common/services/modelServiceImpl.ts +++ b/src/vs/editor/common/services/modelServiceImpl.ts @@ -464,8 +464,6 @@ class ModelSemanticColoring extends Disposable { constructor(model: ITextModel) { super(); - console.log(`ModelSemanticColoring created for ${model.uri}`); - this._model = model; this._fetchSemanticTokens = this._register(new RunOnceScheduler(() => this._fetchSemanticTokensNow(), 500)); this._currentResponse = null; @@ -505,12 +503,6 @@ class ModelSemanticColoring extends Disposable { request.then((res) => { this._currentRequestCancellationTokenSource = null; this._setSemanticTokens(this._currentRequestVersion, res || null); - // if (this._currentResponse) { - // this._currentResponse.dispose(); - // this._currentResponse = null; - // } - // this._currentRequestVersion = -1; - console.log(res); }, (err) => { this._currentRequestCancellationTokenSource = null; errors.onUnexpectedError(err); @@ -524,45 +516,45 @@ class ModelSemanticColoring extends Disposable { this._currentResponse = null; } this._currentResponse = tokens; + if (!this._currentResponse) { + this._model.setSemanticTokens(null); + return; + } // TODO@semantic: diff here and reduce to only really needed tokens... // TODO@semantic: might also be a good idea to split areas... ? - if (this._currentResponse) { - const result: MultilineTokens2[] = []; - for (const area of this._currentResponse.areas) { - const srcTokens = area.data; - const tokenCount = srcTokens.length / 5; - const destTokens = new Uint32Array(4 * tokenCount); - for (let i = 0; i < tokenCount; i++) { - const srcOffset = 5 * i; - const deltaLine = srcTokens[srcOffset]; - const startCharacter = srcTokens[srcOffset + 1]; - const endCharacter = srcTokens[srcOffset + 2]; - // const tokenType = srcTokens[srcOffset + 3]; - // const tokenModifiers = srcTokens[srcOffset + 4]; - // TODO@semantic: map here tokenType and tokenModifiers to metadata + const result: MultilineTokens2[] = []; + for (const area of this._currentResponse.areas) { + const srcTokens = area.data; + const tokenCount = srcTokens.length / 5; + const destTokens = new Uint32Array(4 * tokenCount); + for (let i = 0; i < tokenCount; i++) { + const srcOffset = 5 * i; + const deltaLine = srcTokens[srcOffset]; + const startCharacter = srcTokens[srcOffset + 1]; + const endCharacter = srcTokens[srcOffset + 2]; + // const tokenType = srcTokens[srcOffset + 3]; + // const tokenModifiers = srcTokens[srcOffset + 4]; + // TODO@semantic: map here tokenType and tokenModifiers to metadata - const fontStyle = FontStyle.Italic | FontStyle.Bold | FontStyle.Underline; - const foregroundColorId = 3; - const metadata = ( - (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) - | (foregroundColorId << MetadataConsts.FOREGROUND_OFFSET) - ) >>> 0; + const fontStyle = FontStyle.Italic | FontStyle.Bold | FontStyle.Underline; + const foregroundColorId = 3; + const metadata = ( + (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) + | (foregroundColorId << MetadataConsts.FOREGROUND_OFFSET) + ) >>> 0; - const destOffset = 4 * i; - destTokens[destOffset] = deltaLine; - destTokens[destOffset + 1] = startCharacter; - destTokens[destOffset + 2] = endCharacter; - destTokens[destOffset + 3] = metadata; - } - - const tokens = new MultilineTokens2(area.line, new SparseEncodedTokens(destTokens)); - result.push(tokens); + const destOffset = 4 * i; + destTokens[destOffset] = deltaLine; + destTokens[destOffset + 1] = startCharacter; + destTokens[destOffset + 2] = endCharacter; + destTokens[destOffset + 3] = metadata; } - this._model.setSemanticTokens(result); - } else { - // TODO@semantic: should we clear semantic tokens on the text model here? + const tokens = new MultilineTokens2(area.line, new SparseEncodedTokens(destTokens)); + result.push(tokens); } + + this._model.setSemanticTokens(result); } private _getSemanticColoringProvider(): SemanticColoringProvider | null {