Skip to content

Commit 829a6bd

Browse files
committed
feat(doubt): disable syntax error diagnostics in view editor as TS is not aware of snippets syntax
1 parent 2ce9b40 commit 829a6bd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

typescript-plugin/src/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ export = function ({ typescript: ts }: { typescript: typeof import('typescript/l
6060
return info.languageService.getCompletionsAtPosition(fileName, position, options)
6161
}
6262

63+
const disableSyntaxErrorsInViewEditor = () => {
64+
if (info.project.projectKind !== ts.server.ProjectKind.Inferred) return
65+
const openedFiles = [...(info.project.projectService.openFiles.keys() as any)] as string[]
66+
let ourFileRoot: string | undefined
67+
for (const openedFile of openedFiles) {
68+
const beforeRootIdx = openedFile.indexOf('/^/bettersnippets.virtualsnippets/')
69+
if (beforeRootIdx === -1) continue
70+
ourFileRoot = openedFile.slice(0, beforeRootIdx)
71+
break
72+
}
73+
let currentRoot = info.languageServiceHost.getCurrentDirectory().toLowerCase()
74+
if (currentRoot === '/') currentRoot = ''
75+
if (ourFileRoot === undefined || currentRoot !== ourFileRoot) {
76+
return
77+
}
78+
proxy.getSyntacticDiagnostics = () => []
79+
}
80+
disableSyntaxErrorsInViewEditor()
81+
6382
return proxy
6483
},
6584
onConfigurationChanged(config: any) {

0 commit comments

Comments
 (0)