Skip to content

Commit 96e0fa6

Browse files
perf: 修改为提前返回提升性能 (#216)
1 parent d0fc1b3 commit 96e0fa6

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

packages/language-server/src/patches/patch-semantic.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function patchSemantic(typescriptServices: LanguageServicePlugin[], confi
112112
// eslint-disable-next-line ts/ban-ts-comment
113113
// @ts-expect-error
114114
if (program.isSourceFileDefaultLibrary.patched === true) return program
115-
const originalIsSourceFileDefaultLibrary = program.isSourceFileDefaultLibrary
115+
const originalIsSourceFileDefaultLibrary = program.isSourceFileDefaultLibrary.bind(program)
116116
const patchedIsSourceFileDefaultLibrary = (sourceFile: ets.SourceFile): boolean => {
117117
return sourceFile.fileName.startsWith(config.getSdkPath()) || originalIsSourceFileDefaultLibrary(sourceFile)
118118
}
@@ -141,10 +141,11 @@ export function patchSemantic(typescriptServices: LanguageServicePlugin[], confi
141141
)
142142
// 补丁:将@interface的高亮类型改为ts装饰器的高亮类型
143143
for (let i = 0; i < encodedClassifications.spans.length; i += 3) {
144-
const offset = encodedClassifications.spans[i] // 第1个值:偏移量
145-
const tsClassification = encodedClassifications.spans[i + 2] // 第3个值:编码的分类
144+
const offset = encodedClassifications.spans[i] // 第1个值: offset
145+
const tsClassification = encodedClassifications.spans[i + 2] // 第3个值: ts classification
146+
if (tsClassification !== 256) continue
146147
const annotationDeclaration = findAnnotationOrDecoratorNodeInPosition(offset, sourceFile)
147-
if (annotationDeclaration && tsClassification === 256) encodedClassifications.spans[i + 2] = 2824
148+
if (annotationDeclaration) encodedClassifications.spans[i + 2] = 2824
148149
}
149150
return convertClassificationsToSemanticTokens(document, span, legend, encodedClassifications)
150151
},

0 commit comments

Comments
 (0)