Skip to content

Commit 3d3ebe4

Browse files
(fix): show warnings only for the selected file in cm diagnostics (#521)
* (fix): show warnings only for the selected file in cm diagnostics * add changesets * clean console.log * Fix diagnostic getting out of sync * Minor cleanup * Reduce lint delay --------- Co-authored-by: Puru Vijay <[email protected]>
1 parent 4782b85 commit 3d3ebe4

File tree

4 files changed

+40
-38
lines changed

4 files changed

+40
-38
lines changed

.changeset/shy-bikes-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/repl': patch
3+
---
4+
5+
show warnings only for the selected file

packages/repl/src/lib/CodeMirror.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
svelte: () => import('@replit/codemirror-lang-svelte').then((m) => m.svelte())
231231
},
232232
lint: diagnostics,
233+
lintOptions: { delay: 200 },
233234
autocomplete,
234235
extensions: [watcher],
235236
instanceStore: cmInstance

packages/repl/src/lib/Input/ModuleEditor.svelte

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,34 @@
2424
2525
$: filename = $selected?.name + '.' + $selected?.type;
2626
27-
let error_file = '';
28-
2927
$: if ($bundle) {
3028
error = $bundle?.error;
3129
warnings = $bundle?.warnings ?? [];
32-
if (error || warnings.length > 1) {
33-
error_file = error?.filename ?? warnings[0]?.filename;
34-
}
3530
}
3631
3732
async function diagnostics() {
3833
await $bundling;
39-
return $selected && error_file === get_full_filename($selected)
40-
? /** @type {import('@codemirror/lint').Diagnostic[]} */ ([
41-
...(error
42-
? [
43-
{
44-
from: error.start.character,
45-
to: error.end.character,
46-
severity: 'error',
47-
message: error.message
48-
}
49-
]
50-
: []),
51-
...warnings.map((warning) => ({
52-
from: warning.start.character,
53-
to: warning.end.character,
54-
severity: 'warning',
55-
message: warning.message
56-
}))
57-
])
58-
: [];
34+
35+
return /** @type {import('@codemirror/lint').Diagnostic[]} */ ([
36+
...($selected && error?.filename === get_full_filename($selected)
37+
? [
38+
{
39+
from: error.start.character,
40+
to: error.end.character,
41+
severity: 'error',
42+
message: error.message
43+
}
44+
]
45+
: []),
46+
...warnings
47+
.filter((warning) => $selected && warning.filename === get_full_filename($selected))
48+
.map((warning) => ({
49+
from: warning.start.character,
50+
to: warning.end.character,
51+
severity: 'warning',
52+
message: warning.message
53+
}))
54+
]);
5955
}
6056
</script>
6157

packages/repl/src/routes/+page.svelte

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
name: 'App',
1414
type: 'svelte',
1515
source:
16-
`<scr` +
17-
`ipt>
18-
let name = 'world';
19-
</scr` +
20-
`ipt>
21-
22-
<h1>Hello {name}!</h1>
23-
24-
<input type="button" on:click on:keypress value="press me"/>
25-
`
16+
'<scri' +
17+
"pt>\n\timport Timeline from './Timeline.svelte'\n\timport Sequence from './Sequence.svelte'\n\t\n\timport { tweened } from 'svelte/motion';\n</sc" +
18+
'ript>\n\n<Timeline>\n\t<Sequence let:fps let:frame>\n\t\t<div style="height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;">\n\t\t\t<h1 style="opacity: {Math.min(1, frame / fps)}; transform: translateY({Math.cos(frame/15) * 10}px);">\n\t\t\t\tHello Svelte\n\t\t\t</h1>\n\t\t\t<p style="opacity: {Math.min(1, frame / fps)}; transform: translateY({Math.cos((frame - 5)/15) * 10}px);">\n\t\t\t\tThis is a test.\n\t\t\t</p>\n\t\t</div>\n\t</Sequence>\n</Timeline>\n'
19+
},
20+
{
21+
name: 'Sequence',
22+
type: 'svelte',
23+
source:
24+
'<scri' +
25+
"pt>\n\timport { onMount, onDestroy, getContext } from 'svelte';\n\t\n\tconst timeline = getContext('x:timeline');\n\t\n\t$: ({ width, height, fps } = $timeline);\n\t\n\texport let duration = fps * 10;\n\texport let start = 0;\n\texport let track = 1;\n\t\n\t$: frame = $timeline.frame - start;\n</sc" +
26+
'ript>\n\n{#if timeline}\n\t<div class="sequence" style="width: {width}px; height: {height}px; border: 1px solid #ddd;">\n\t\t<slot {width} {height} {fps} {duration} {frame} />\n\t</div>\n{/if}\n'
2627
},
2728
{
28-
name: 'B',
29+
name: 'Timeline',
2930
type: 'svelte',
30-
source: `<input type="button" on:click on:keypress value="press me"/>
31-
`
31+
source: ''
3232
}
3333
]
3434
});

0 commit comments

Comments
 (0)