Skip to content

Commit 8466d8e

Browse files
fix: attribute deletion (#513)
* Working but not cool * Fix it properly * add changesets * remove unused variable * update changesets * neocodemirror 0.0.15 --------- Co-authored-by: Puru Vijay <[email protected]>
1 parent 242e1fa commit 8466d8e

File tree

8 files changed

+36
-92
lines changed

8 files changed

+36
-92
lines changed

.changeset/sweet-pianos-sniff.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+
manage diagnostics asyncronously with linter

packages/repl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@codemirror/view": "^6.14.0",
7474
"@jridgewell/sourcemap-codec": "^1.4.15",
7575
"@lezer/highlight": "^1.1.6",
76-
"@neocodemirror/svelte": "0.0.14",
76+
"@neocodemirror/svelte": "0.0.15",
7777
"@replit/codemirror-lang-svelte": "^6.0.0",
7878
"@rich_harris/svelte-split-pane": "^1.1.1",
7979
"@rollup/browser": "^3.25.3",

packages/repl/src/lib/CodeMirror.svelte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
<script>
66
import { historyField } from '@codemirror/commands';
7-
import { codeFolding } from '@codemirror/language';
87
import { EditorState, Range, StateEffect, StateEffectType, StateField } from '@codemirror/state';
98
import { Decoration, EditorView } from '@codemirror/view';
109
import { codemirror, withCodemirrorInstance } from '@neocodemirror/svelte';
@@ -16,8 +15,8 @@
1615
/** @type {import('./types').StartOrEnd | null} */
1716
export let errorLoc = null;
1817
19-
/** @type {import('@codemirror/lint').Diagnostic[]} */
20-
export let diagnostics = [];
18+
/** @type {import('@codemirror/lint').LintSource>} */
19+
export let diagnostics;
2120
2221
export let readonly = false;
2322
export let tab = true;
@@ -230,9 +229,9 @@
230229
css: () => import('@codemirror/lang-css').then((m) => m.css()),
231230
svelte: () => import('@replit/codemirror-lang-svelte').then((m) => m.svelte())
232231
},
232+
lint: diagnostics,
233233
autocomplete,
234-
extensions: [codeFolding(), watcher],
235-
diagnostics,
234+
extensions: [watcher],
236235
instanceStore: cmInstance
237236
}}
238237
on:codemirror:textChange={({ detail: value }) => {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$module_editor?.focus();
1515
}
1616
17-
const { bundle, handle_change, module_editor, selected } = get_repl_context();
17+
const { bundle, handle_change, module_editor, selected, bundling } = get_repl_context();
1818
1919
/** @type {import('$lib/types').Error | null | undefined} */
2020
let error = null;
@@ -29,14 +29,14 @@
2929
$: if ($bundle) {
3030
error = $bundle?.error;
3131
warnings = $bundle?.warnings ?? [];
32-
3332
if (error || warnings.length > 1) {
3433
error_file = error?.filename ?? warnings[0]?.filename;
3534
}
3635
}
3736
38-
$: diagnostics =
39-
$selected && error_file === get_full_filename($selected)
37+
async function diagnostics() {
38+
await $bundling;
39+
return $selected && error_file === get_full_filename($selected)
4040
? /** @type {import('@codemirror/lint').Diagnostic[]} */ ([
4141
...(error
4242
? [
@@ -56,6 +56,7 @@
5656
}))
5757
])
5858
: [];
59+
}
5960
</script>
6061
6162
<div class="editor-wrapper">

packages/repl/src/lib/Repl.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,16 @@
150150
/** @type {ReplContext['bundler']} */
151151
const bundler = writable(null);
152152
153+
/** @type {ReplContext['bundling']} */
154+
const bundling = writable(new Promise(() => {}));
155+
153156
set_repl_context({
154157
files,
155158
selected_name,
156159
selected,
157160
bundle,
158161
bundler,
162+
bundling,
159163
compile_options,
160164
cursor_pos,
161165
module_editor,
@@ -175,8 +179,13 @@
175179
let current_token;
176180
async function rebundle() {
177181
const token = (current_token = Symbol());
182+
let resolver = () => {};
183+
$bundling = new Promise((resolve) => {
184+
resolver = resolve;
185+
});
178186
const result = await $bundler?.bundle($files);
179187
if (result && token === current_token) $bundle = result;
188+
resolver();
180189
}
181190
182191
let is_select_changing = false;

packages/repl/src/lib/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type ReplState = {
5454
selected_name: string;
5555
selected: File | null;
5656
bundle: Bundle | null;
57+
bundling: Promise<void>;
5758
bundler: import('./Bundler').default | null;
5859
compile_options: CompileOptions;
5960
cursor_pos: number;
@@ -67,6 +68,7 @@ export type ReplContext = {
6768
selected_name: Writable<ReplState['selected_name']>;
6869
selected: Readable<ReplState['selected']>;
6970
bundle: Writable<ReplState['bundle']>;
71+
bundling: Writable<ReplState['bundling']>;
7072
bundler: Writable<ReplState['bundler']>;
7173
compile_options: Writable<ReplState['compile_options']>;
7274
cursor_pos: Writable<ReplState['cursor_pos']>;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
source:
1616
`<scr` +
1717
`ipt>
18-
import B from './B.svelte';
1918
let name = 'world';
2019
</scr` +
2120
`ipt>
2221
23-
<h1>Hello {name}!</h1>`
22+
<h1>Hello {name}!</h1>
23+
24+
<input type="button" on:click on:keypress value="press me"/>
25+
`
2426
},
2527
{
2628
name: 'B',
2729
type: 'svelte',
28-
source: `B`
30+
source: `<input type="button" on:click on:keypress value="press me"/>
31+
`
2932
}
3033
]
3134
});

pnpm-lock.yaml

Lines changed: 4 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)