diff --git a/packages/language-server/src/plugins/typescript/features/utils.ts b/packages/language-server/src/plugins/typescript/features/utils.ts index db5321495..85c29d218 100644 --- a/packages/language-server/src/plugins/typescript/features/utils.ts +++ b/packages/language-server/src/plugins/typescript/features/utils.ts @@ -75,11 +75,10 @@ export function isComponentAtPosition( * because it's purely generated. */ export function isInGeneratedCode(text: string, start: number, end: number) { - const lineStart = text.lastIndexOf('\n', start); - const lineEnd = text.indexOf('\n', end); - const lastStart = text.substring(lineStart, start).lastIndexOf('/*Ωignore_startΩ*/'); - const lastEnd = text.substring(lineStart, start).lastIndexOf('/*Ωignore_endΩ*/'); - return lastStart > lastEnd && text.substring(end, lineEnd).includes('/*Ωignore_endΩ*/'); + const lastStart = text.lastIndexOf('/*Ωignore_startΩ*/', start); + const lastEnd = text.lastIndexOf('/*Ωignore_endΩ*/', start); + const nextEnd = text.indexOf('/*Ωignore_endΩ*/', end); + return lastStart > lastEnd && lastStart < nextEnd; } /** diff --git a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts index 3f265503d..ed7c39058 100644 --- a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts @@ -808,11 +808,11 @@ describe('DiagnosticsProvider', () => { range: { end: { character: 13, - line: 3 + line: 4 }, start: { character: 12, - line: 3 + line: 4 } }, severity: 1, @@ -825,11 +825,11 @@ describe('DiagnosticsProvider', () => { range: { end: { character: 6, - line: 4 + line: 5 }, start: { character: 5, - line: 4 + line: 5 } }, severity: 1, @@ -842,11 +842,11 @@ describe('DiagnosticsProvider', () => { range: { end: { character: 10, - line: 8 + line: 9 }, start: { character: 9, - line: 8 + line: 9 } }, severity: 1, @@ -859,11 +859,28 @@ describe('DiagnosticsProvider', () => { range: { end: { character: 10, - line: 9 + line: 10 }, start: { character: 9, - line: 9 + line: 10 + } + }, + severity: 1, + source: 'ts', + tags: [] + }, + { + code: 2322, + message: 'Type \'"food"\' is not assignable to type \'"foo" | "bar"\'.', + range: { + start: { + character: 2, + line: 15 + }, + end: { + character: 9, + line: 15 } }, severity: 1, diff --git a/packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated-imported.svelte b/packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated-imported.svelte new file mode 100644 index 000000000..5f02789e0 --- /dev/null +++ b/packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated-imported.svelte @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated.svelte b/packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated.svelte index 1441cf0f8..c89c9ff11 100644 --- a/packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated.svelte +++ b/packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated.svelte @@ -1,4 +1,5 @@ {#if typeof a === 'string'} @@ -10,3 +11,11 @@ {b} {/if} {/if} + + {}} +/>