|
|
|
|
@ -1,62 +1,49 @@
|
|
|
|
|
<script>
|
|
|
|
|
import { get_repl_context } from '$lib/context.js';
|
|
|
|
|
import { get_full_filename } from '$lib/utils.js';
|
|
|
|
|
import CodeMirror from '../CodeMirror.svelte';
|
|
|
|
|
|
|
|
|
|
/** @type {boolean} */
|
|
|
|
|
export let autocomplete;
|
|
|
|
|
|
|
|
|
|
/** @type {any} */ // TODO
|
|
|
|
|
export let error;
|
|
|
|
|
|
|
|
|
|
/** @type {any[]} */ // TODO
|
|
|
|
|
export let warnings;
|
|
|
|
|
|
|
|
|
|
export function focus() {
|
|
|
|
|
$module_editor?.focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { bundle, handle_change, module_editor, selected, bundling } = get_repl_context();
|
|
|
|
|
|
|
|
|
|
async function diagnostics() {
|
|
|
|
|
/** @type {import('@codemirror/lint').Diagnostic[]} */
|
|
|
|
|
const diagnostics = [];
|
|
|
|
|
|
|
|
|
|
if (!$selected || !$bundle) return diagnostics;
|
|
|
|
|
|
|
|
|
|
await $bundling;
|
|
|
|
|
|
|
|
|
|
const filename = get_full_filename($selected);
|
|
|
|
|
const { handle_change, module_editor } = get_repl_context();
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
$bundle.error &&
|
|
|
|
|
$bundle.error.filename === filename &&
|
|
|
|
|
$bundle.error.start &&
|
|
|
|
|
$bundle.error.end
|
|
|
|
|
) {
|
|
|
|
|
diagnostics.push({
|
|
|
|
|
from: $bundle.error.start.character,
|
|
|
|
|
to: $bundle.error.end.character,
|
|
|
|
|
<div class="editor-wrapper">
|
|
|
|
|
<div class="editor notranslate" translate="no">
|
|
|
|
|
<CodeMirror
|
|
|
|
|
bind:this={$module_editor}
|
|
|
|
|
{autocomplete}
|
|
|
|
|
diagnostics={() => {
|
|
|
|
|
if (error) {
|
|
|
|
|
return [{
|
|
|
|
|
severity: 'error',
|
|
|
|
|
message: $bundle.error.message
|
|
|
|
|
});
|
|
|
|
|
from: error.position[0],
|
|
|
|
|
to: error.position[1],
|
|
|
|
|
message: error.message
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const warning of $bundle.warnings) {
|
|
|
|
|
if (warning.filename === filename) {
|
|
|
|
|
diagnostics.push({
|
|
|
|
|
if (warnings) {
|
|
|
|
|
return warnings.map((warning) => ({
|
|
|
|
|
severity: 'warning',
|
|
|
|
|
from: warning.start.character,
|
|
|
|
|
to: warning.end.character,
|
|
|
|
|
severity: 'warning',
|
|
|
|
|
message: warning.message
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
message: warning.message,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return diagnostics;
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="editor-wrapper">
|
|
|
|
|
<div class="editor notranslate" translate="no">
|
|
|
|
|
<CodeMirror
|
|
|
|
|
bind:this={$module_editor}
|
|
|
|
|
{autocomplete}
|
|
|
|
|
diagnostics={$selected && $bundle ? diagnostics : () => []}
|
|
|
|
|
return [];
|
|
|
|
|
}}
|
|
|
|
|
on:change={handle_change}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|