-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypescriptPlugin.ts
More file actions
46 lines (40 loc) · 2.2 KB
/
typescriptPlugin.ts
File metadata and controls
46 lines (40 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Position, type LanguageServicePlugin, type LanguageServicePluginInstance } from '@volar/language-server';
import { create as createTypeScriptServices } from 'volar-service-typescript';
export const create = (ts: typeof import('typescript')): LanguageServicePlugin[] => {
const tsServicePlugins = createTypeScriptServices(ts as typeof import('typescript'), {});
return tsServicePlugins.map<LanguageServicePlugin>((plugin) => {
if (plugin.name === 'typescript-semantic') {
return {
...plugin,
create(context): LanguageServicePluginInstance {
const typeScriptPlugin = plugin.create(context);
return {
...typeScriptPlugin,
async provideDiagnostics(document, token): Promise<import('@volar/language-server').Diagnostic[] | null> {
const diagnostics = await typeScriptPlugin.provideDiagnostics?.(document, token);
if (!diagnostics) return null;
const { uri } = document;
// Adjust diagnostic range for 'include_' URIs
if (uri.includes('include_')) {
const match = uri.match(/include_(\d+)_(\d+)/);
if (match) {
const to = parseInt(match[2], 10);
diagnostics.forEach(diagnostic => {
diagnostic.range.start = Position.create(0, 0);
diagnostic.range.end = Position.create(0, to);
});
}
}
// Filter out specific diagnostics for 'tsfso' URIs
const filteredDiagnostics = uri.includes('tsfso')
? diagnostics.filter(d => d.code !== 1375)
: diagnostics;
return filteredDiagnostics;
}
};
},
};
}
return plugin;
});
};