Skip to content

Commit 4722e67

Browse files
committed
feat: disableUselessHighlighting (disabled by default). I personally really love this feature! Simple but effective
1 parent 818a1a5 commit 4722e67

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/configurationType.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ export type Configuration = {
239239
* @default true
240240
*/
241241
switchExcludeCoveredCases: boolean
242+
/**
243+
* Disable useless highlighting,
244+
* @default disable
245+
*/
246+
disableUselessHighlighting: 'disable' | 'inJsxArttributeStrings' | 'inAllStrings'
242247
/**
243248
* Improve JSX attribute completions:
244249
* - enable builtin jsx attribute completion fix

typescript/src/documentHighlights.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { GetConfig } from './types'
2+
import { findChildContainingPosition } from './utils'
3+
4+
export default (proxy: ts.LanguageService, languageService: ts.LanguageService, c: GetConfig) => {
5+
proxy.getDocumentHighlights = (fileName, position, filesToSearch) => {
6+
const prior = languageService.getDocumentHighlights(fileName, position, filesToSearch)
7+
if (!prior) return
8+
if (prior.length !== 1) return prior
9+
const node = findChildContainingPosition(ts, languageService.getProgram()!.getSourceFile(fileName)!, position)
10+
if (!node) return prior
11+
if (c('disableUselessHighlighting') !== 'disable') {
12+
if (ts.isStringLiteralLike(node)) {
13+
if (c('disableUselessHighlighting') === 'inAllStrings') return
14+
else if (ts.isJsxAttribute(node.parent)) return
15+
}
16+
}
17+
return prior
18+
}
19+
}

typescript/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import decorateCodeFixes from './codeFixes'
1717
import decorateReferences from './references'
1818
import handleSpecialCommand from './specialCommands/handle'
1919
import decorateDefinitions from './definitions'
20+
import decorateDocumentHighlights from './documentHighlights'
2021

2122
const thisPluginMarker = Symbol('__essentialPluginsMarker__')
2223

@@ -148,6 +149,7 @@ export = ({ typescript }: { typescript: typeof ts }) => {
148149
decorateSemanticDiagnostics(proxy, info, c)
149150
decorateDefinitions(proxy, info, c)
150151
decorateReferences(proxy, info.languageService, c)
152+
decorateDocumentHighlights(proxy, info.languageService, c)
151153

152154
if (!__WEB__) {
153155
// dedicated syntax server (which is enabled by default), which fires navtree doesn't seem to receive onConfigurationChanged

0 commit comments

Comments
 (0)