microsoft / TypeScript-TmLanguage

TextMate grammar files for TypeScript for VS Code, Sublime Text, and Atom.
MIT License
415 stars 130 forks source link

Unexpected coloring of the token in the editor #1003

Open aiday-mar opened 1 year ago

aiday-mar commented 1 year ago

While examining code in the diff editor, I noticed that the color schema appears to be off. Notice how in the following image, the this token on line 322 is colored green while it should actually be a dark blue (like the other this tokens).

Screenshot 2023-08-25 at 14 22 40

I was using the following code:

Code ``` private _renderFoldingIconForLine(container: HTMLSpanElement, foldingModel: FoldingModel | null | undefined, index: number, line: number): FoldingIcon | undefined { const showFoldingControls: 'mouseover' | 'always' | 'never' = this._editor.getOption(EditorOption.showFoldingControls); if (!foldingModel || showFoldingControls === 'never') { return; } const foldingRegions = foldingModel.regions; const indexOfFoldingRegion = foldingRegions.findRange(line); const startLineNumber = foldingRegions.getStartLineNumber(indexOfFoldingRegion); const isFoldingScope = line === startLineNumber; if (!isFoldingScope) { return; } const foldingIconNode = container.appendChild(document.createElement('div')); const isCollapsed = foldingRegions.isCollapsed(indexOfFoldingRegion); foldingIconNode.className = ThemeIcon.asClassName(isCollapsed ? foldingCollapsedIcon : foldingExpandedIcon); const foldingIcon = new FoldingIcon(foldingIconNode, isCollapsed); foldingIcon.setVisible(isCollapsed || showFoldingControls === 'always'); foldingIcon.setTransitionRequired(true); this._foldingIconStore.add(dom.addDisposableListener(foldingIconNode, dom.EventType.CLICK, () => { toggleCollapseState(foldingModel, Number.MAX_VALUE, [line]); foldingIcon.isCollapsed = !isCollapsed; const scrollTop = ( isCollapsed ? this._editor.getTopForLineNumber(startLineNumber) : this._editor.getTopForLineNumber(foldingRegions.getEndLineNumber(indexOfFoldingRegion))) - this._lineHeight * index + 1; this._editor.setScrollTop(scrollTop); })); return foldingIcon; } ```
aiday-mar commented 1 year ago

Hey @hediet, not sure if I should assign this to you? Feel free to change assignment.

hediet commented 1 year ago

Code_-_Insiders_U8h55dYcAo

When I add a whitespace after ? it works:

Code_-_Insiders_5rTL88WDav

globalThis.x = (
   globalThis ? 
   1 : foobar
);
aiday-mar commented 1 year ago

I see, the color schema is correct now too in the editor. I suppose that it had something to do with saving the document or formatting the document for the token colors to be rendered appropriately. I'll close the issue.

hediet commented 1 year ago

I think this is indeed a bug of the typescript grammar!