Skip to content

Commit 1782cef

Browse files
authored
(fix) ignore multiline generated code (#1145)
#1113
1 parent ab55817 commit 1782cef

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ export function isComponentAtPosition(
7575
* because it's purely generated.
7676
*/
7777
export function isInGeneratedCode(text: string, start: number, end: number) {
78-
const lineStart = text.lastIndexOf('\n', start);
79-
const lineEnd = text.indexOf('\n', end);
80-
const lastStart = text.substring(lineStart, start).lastIndexOf('/*Ωignore_startΩ*/');
81-
const lastEnd = text.substring(lineStart, start).lastIndexOf('/*Ωignore_endΩ*/');
82-
return lastStart > lastEnd && text.substring(end, lineEnd).includes('/*Ωignore_endΩ*/');
78+
const lastStart = text.lastIndexOf('/*Ωignore_startΩ*/', start);
79+
const lastEnd = text.lastIndexOf('/*Ωignore_endΩ*/', start);
80+
const nextEnd = text.indexOf('/*Ωignore_endΩ*/', end);
81+
return lastStart > lastEnd && lastStart < nextEnd;
8382
}
8483

8584
/**

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,11 @@ describe('DiagnosticsProvider', () => {
808808
range: {
809809
end: {
810810
character: 13,
811-
line: 3
811+
line: 4
812812
},
813813
start: {
814814
character: 12,
815-
line: 3
815+
line: 4
816816
}
817817
},
818818
severity: 1,
@@ -825,11 +825,11 @@ describe('DiagnosticsProvider', () => {
825825
range: {
826826
end: {
827827
character: 6,
828-
line: 4
828+
line: 5
829829
},
830830
start: {
831831
character: 5,
832-
line: 4
832+
line: 5
833833
}
834834
},
835835
severity: 1,
@@ -842,11 +842,11 @@ describe('DiagnosticsProvider', () => {
842842
range: {
843843
end: {
844844
character: 10,
845-
line: 8
845+
line: 9
846846
},
847847
start: {
848848
character: 9,
849-
line: 8
849+
line: 9
850850
}
851851
},
852852
severity: 1,
@@ -859,11 +859,28 @@ describe('DiagnosticsProvider', () => {
859859
range: {
860860
end: {
861861
character: 10,
862-
line: 9
862+
line: 10
863863
},
864864
start: {
865865
character: 9,
866-
line: 9
866+
line: 10
867+
}
868+
},
869+
severity: 1,
870+
source: 'ts',
871+
tags: []
872+
},
873+
{
874+
code: 2322,
875+
message: 'Type \'"food"\' is not assignable to type \'"foo" | "bar"\'.',
876+
range: {
877+
start: {
878+
character: 2,
879+
line: 15
880+
},
881+
end: {
882+
character: 9,
883+
line: 15
867884
}
868885
},
869886
severity: 1,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script lang="ts">
2+
export let variant: "foo" | "bar";
3+
export let style: string;
4+
</script>

packages/language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-ignore-generated.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import Comp from './diagnostics-ignore-generated-imported.svelte';
23
</script>
34

45
{#if typeof a === 'string'}
@@ -10,3 +11,11 @@
1011
{b}
1112
{/if}
1213
{/if}
14+
15+
<Comp
16+
variant="food"
17+
style={`${
18+
1
19+
}`}
20+
on:click={() => {}}
21+
/>

0 commit comments

Comments
 (0)