Skip to content

Commit 06fad25

Browse files
committed
Fixes microsoft#138185. Unicode highlight hover is no longer shown for unicode characters in comments.
1 parent 94ab8f1 commit 06fad25

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

src/vs/editor/common/viewModel/viewModelDecorations.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,8 @@ export class ViewModelDecorations implements IDisposable {
122122
let modelDecoration = modelDecorations[i];
123123
let decorationOptions = modelDecoration.options;
124124

125-
if (decorationOptions.hideInCommentTokens) {
126-
let allTokensComments = testTokensInRange(
127-
this.model,
128-
modelDecoration.range,
129-
(tokenType) => tokenType === StandardTokenType.Comment
130-
);
131-
132-
if (allTokensComments) {
133-
continue;
134-
}
125+
if (!isModelDecorationVisible(this.model, modelDecoration)) {
126+
continue;
135127
}
136128

137129
let viewModelDecoration = this._getOrCreateViewModelDecoration(modelDecoration);
@@ -176,6 +168,21 @@ export class ViewModelDecorations implements IDisposable {
176168
}
177169
}
178170

171+
export function isModelDecorationVisible(model: ITextModel, decoration: IModelDecoration): boolean {
172+
if (decoration.options.hideInCommentTokens) {
173+
const allTokensAreComments = testTokensInRange(
174+
model,
175+
decoration.range,
176+
(tokenType) => tokenType === StandardTokenType.Comment
177+
);
178+
if (allTokensAreComments) {
179+
return false;
180+
}
181+
}
182+
183+
return true;
184+
}
185+
179186
/**
180187
* Calls the callback for every token that intersects the range.
181188
* If the callback returns `false`, iteration stops and `false` is returned.

src/vs/editor/contrib/unicodeHighlighter/unicodeHighlighter.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
2020
import { UnicodeHighlighterOptions, UnicodeHighlighterReason, UnicodeHighlighterReasonKind, UnicodeTextModelHighlighter } from 'vs/editor/common/modes/unicodeTextModelHighlighter';
2121
import { IEditorWorkerService, IUnicodeHighlightsResult } from 'vs/editor/common/services/editorWorkerService';
2222
import { IModeService } from 'vs/editor/common/services/modeService';
23+
import { isModelDecorationVisible } from 'vs/editor/common/viewModel/viewModelDecorations';
2324
import { HoverAnchor, HoverAnchorType, IEditorHover, IEditorHoverParticipant, IEditorHoverStatusBar, IHoverPart } from 'vs/editor/contrib/hover/hoverTypes';
2425
import { MarkdownHover, renderMarkdownHovers } from 'vs/editor/contrib/hover/markdownHoverParticipant';
2526
import { BannerController } from 'vs/editor/contrib/unicodeHighlighter/bannerController';
@@ -255,8 +256,21 @@ class DocumentUnicodeHighlighter extends Disposable {
255256
if (!this._decorationIds.has(decorationId)) {
256257
return null;
257258
}
258-
const range = this._editor.getModel().getDecorationRange(decorationId)!;
259-
const text = this._editor.getModel().getValueInRange(range);
259+
const model = this._editor.getModel();
260+
const range = model.getDecorationRange(decorationId)!;
261+
if (
262+
!isModelDecorationVisible(model, {
263+
range: range,
264+
options: this._options.includeComments
265+
? DECORATION
266+
: DECORATION_HIDE_IN_COMMENTS,
267+
id: decorationId,
268+
ownerId: 0,
269+
})
270+
) {
271+
return null;
272+
}
273+
const text = model.getValueInRange(range);
260274
return {
261275
reason: computeReason(text, this._options)!,
262276
};
@@ -341,8 +355,21 @@ class ViewportUnicodeHighlighter extends Disposable {
341355
if (!this._decorationIds.has(decorationId)) {
342356
return null;
343357
}
344-
const range = this._editor.getModel().getDecorationRange(decorationId)!;
345-
const text = this._editor.getModel().getValueInRange(range);
358+
const model = this._editor.getModel();
359+
const range = model.getDecorationRange(decorationId)!;
360+
const text = model.getValueInRange(range);
361+
if (
362+
!isModelDecorationVisible(model, {
363+
range: range,
364+
options: this._options.includeComments
365+
? DECORATION
366+
: DECORATION_HIDE_IN_COMMENTS,
367+
id: decorationId,
368+
ownerId: 0,
369+
})
370+
) {
371+
return null;
372+
}
346373
return {
347374
reason: computeReason(text, this._options)!,
348375
};

0 commit comments

Comments
 (0)