Skip to content

Commit

Permalink
fix: attribute deletion (#513)
Browse files Browse the repository at this point in the history
* Working but not cool

* Fix it properly

* add changesets

* remove unused variable

* update changesets

* neocodemirror 0.0.15

---------

Co-authored-by: Puru Vijay <devpuruvj@gmail.com>
  • Loading branch information
paoloricciuti and PuruVJ authored Jul 2, 2023
1 parent 242e1fa commit 8466d8e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 92 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-pianos-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/repl': patch
---

manage diagnostics asyncronously with linter
2 changes: 1 addition & 1 deletion packages/repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@codemirror/view": "^6.14.0",
"@jridgewell/sourcemap-codec": "^1.4.15",
"@lezer/highlight": "^1.1.6",
"@neocodemirror/svelte": "0.0.14",
"@neocodemirror/svelte": "0.0.15",
"@replit/codemirror-lang-svelte": "^6.0.0",
"@rich_harris/svelte-split-pane": "^1.1.1",
"@rollup/browser": "^3.25.3",
Expand Down
9 changes: 4 additions & 5 deletions packages/repl/src/lib/CodeMirror.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<script>
import { historyField } from '@codemirror/commands';
import { codeFolding } from '@codemirror/language';
import { EditorState, Range, StateEffect, StateEffectType, StateField } from '@codemirror/state';
import { Decoration, EditorView } from '@codemirror/view';
import { codemirror, withCodemirrorInstance } from '@neocodemirror/svelte';
Expand All @@ -16,8 +15,8 @@
/** @type {import('./types').StartOrEnd | null} */
export let errorLoc = null;
/** @type {import('@codemirror/lint').Diagnostic[]} */
export let diagnostics = [];
/** @type {import('@codemirror/lint').LintSource>} */
export let diagnostics;
export let readonly = false;
export let tab = true;
Expand Down Expand Up @@ -230,9 +229,9 @@
css: () => import('@codemirror/lang-css').then((m) => m.css()),
svelte: () => import('@replit/codemirror-lang-svelte').then((m) => m.svelte())
},
lint: diagnostics,
autocomplete,
extensions: [codeFolding(), watcher],
diagnostics,
extensions: [watcher],
instanceStore: cmInstance
}}
on:codemirror:textChange={({ detail: value }) => {
Expand Down
9 changes: 5 additions & 4 deletions packages/repl/src/lib/Input/ModuleEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$module_editor?.focus();
}
const { bundle, handle_change, module_editor, selected } = get_repl_context();
const { bundle, handle_change, module_editor, selected, bundling } = get_repl_context();
/** @type {import('$lib/types').Error | null | undefined} */
let error = null;
Expand All @@ -29,14 +29,14 @@
$: if ($bundle) {
error = $bundle?.error;
warnings = $bundle?.warnings ?? [];
if (error || warnings.length > 1) {
error_file = error?.filename ?? warnings[0]?.filename;
}
}
$: diagnostics =
$selected && error_file === get_full_filename($selected)
async function diagnostics() {
await $bundling;
return $selected && error_file === get_full_filename($selected)
? /** @type {import('@codemirror/lint').Diagnostic[]} */ ([
...(error
? [
Expand All @@ -56,6 +56,7 @@
}))
])
: [];
}
</script>
<div class="editor-wrapper">
Expand Down
9 changes: 9 additions & 0 deletions packages/repl/src/lib/Repl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,16 @@
/** @type {ReplContext['bundler']} */
const bundler = writable(null);
/** @type {ReplContext['bundling']} */
const bundling = writable(new Promise(() => {}));
set_repl_context({
files,
selected_name,
selected,
bundle,
bundler,
bundling,
compile_options,
cursor_pos,
module_editor,
Expand All @@ -175,8 +179,13 @@
let current_token;
async function rebundle() {
const token = (current_token = Symbol());
let resolver = () => {};
$bundling = new Promise((resolve) => {
resolver = resolve;
});
const result = await $bundler?.bundle($files);
if (result && token === current_token) $bundle = result;
resolver();
}
let is_select_changing = false;
Expand Down
2 changes: 2 additions & 0 deletions packages/repl/src/lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type ReplState = {
selected_name: string;
selected: File | null;
bundle: Bundle | null;
bundling: Promise<void>;
bundler: import('./Bundler').default | null;
compile_options: CompileOptions;
cursor_pos: number;
Expand All @@ -67,6 +68,7 @@ export type ReplContext = {
selected_name: Writable<ReplState['selected_name']>;
selected: Readable<ReplState['selected']>;
bundle: Writable<ReplState['bundle']>;
bundling: Writable<ReplState['bundling']>;
bundler: Writable<ReplState['bundler']>;
compile_options: Writable<ReplState['compile_options']>;
cursor_pos: Writable<ReplState['cursor_pos']>;
Expand Down
9 changes: 6 additions & 3 deletions packages/repl/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
source:
`<scr` +
`ipt>
import B from './B.svelte';
let name = 'world';
</scr` +
`ipt>
<h1>Hello {name}!</h1>`
<h1>Hello {name}!</h1>
<input type="button" on:click on:keypress value="press me"/>
`
},
{
name: 'B',
type: 'svelte',
source: `B`
source: `<input type="button" on:click on:keypress value="press me"/>
`
}
]
});
Expand Down
83 changes: 4 additions & 79 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit 8466d8e

@vercel
Copy link

@vercel vercel bot commented on 8466d8e Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hn – ./sites/hn.svelte.dev

hn-git-master-svelte.vercel.app
hn.svelte.dev
sites-zeta.vercel.app
hn-svelte.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 8466d8e Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

repl – ./packages/repl

repl-git-master-svelte.vercel.app
repl-svelte.vercel.app
repl-zeta.vercel.app
svelte-rappel.vercel.app

Please sign in to comment.