Skip to content

Commit b41582b

Browse files
authored
(feat) better diagnostics (#760)
#753, #718 - make it more clear that the JSX-related message is the underlying error to diminish confusion - add suggestion to ts error
1 parent 7eb0f63 commit b41582b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

packages/language-server/src/plugins/typescript/features/DiagnosticsProvider.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,37 @@ function enhanceIfNecessary(diagnostic: Diagnostic): Diagnostic {
130130
message:
131131
'Type definitions are missing for this Svelte Component. ' +
132132
// eslint-disable-next-line max-len
133-
'It needs a class definition with at least the property \'$$prop_def\' which should contain a map of input property definitions.\n' +
133+
"It needs a class definition with at least the property '$$prop_def' which should contain a map of input property definitions.\n" +
134134
'Example:\n' +
135-
'class ComponentName { $$prop_def: { propertyName: string; } }\n\n' +
135+
' class ComponentName { $$prop_def: { propertyName: string; } }\n' +
136+
'If you are using Svelte 3.31+, use SvelteComponentTyped:\n' +
137+
' import type { SvelteComponentTyped } from "svelte";\n' +
138+
' class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}\n\n' +
139+
'Underlying error:\n' +
136140
diagnostic.message
137141
};
138142
}
139143

144+
if (diagnostic.code === 2607) {
145+
return {
146+
...diagnostic,
147+
message:
148+
'Element does not support attributes because ' +
149+
'type definitions are missing for this Svelte Component or element cannot be used as such.\n\n' +
150+
'Underlying error:\n' +
151+
diagnostic.message
152+
};
153+
}
154+
155+
if (diagnostic.code === 1184) {
156+
return {
157+
...diagnostic,
158+
message:
159+
diagnostic.message +
160+
'\nIf this is a declare statement, move it into <script context="module">..</script>'
161+
};
162+
}
163+
140164
return diagnostic;
141165
}
142166

0 commit comments

Comments
 (0)