Fix keyboard shortcuts and remove llm garbage
This commit is contained in:
parent
94454968e5
commit
dc766cbfa3
|
|
@ -32,11 +32,18 @@ import {
|
||||||
import { languages } from "@codemirror/language-data";
|
import { languages } from "@codemirror/language-data";
|
||||||
import { autocompletion, closeBrackets } from "@codemirror/autocomplete";
|
import { autocompletion, closeBrackets } from "@codemirror/autocomplete";
|
||||||
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
|
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
|
||||||
|
import { lintKeymap } from "@codemirror/lint";
|
||||||
import van from "vanjs-core";
|
import van from "vanjs-core";
|
||||||
import { Displayable } from "./displayable";
|
import { Displayable } from "./displayable";
|
||||||
import { createLspExtension } from "./lsp";
|
import { createLspExtension } from "./lsp";
|
||||||
|
|
||||||
import { OpenFile } from "./filestate";
|
import { OpenFile } from "./filestate";
|
||||||
|
import {
|
||||||
|
findReferencesKeymap,
|
||||||
|
formatKeymap,
|
||||||
|
jumpToDefinitionKeymap,
|
||||||
|
renameKeymap,
|
||||||
|
} from "@codemirror/lsp-client";
|
||||||
|
|
||||||
const fixedHeightEditor = EditorView.theme({
|
const fixedHeightEditor = EditorView.theme({
|
||||||
"&": {
|
"&": {
|
||||||
|
|
@ -97,6 +104,12 @@ export class Editor extends Displayable {
|
||||||
...defaultKeymap,
|
...defaultKeymap,
|
||||||
...searchKeymap,
|
...searchKeymap,
|
||||||
...foldKeymap,
|
...foldKeymap,
|
||||||
|
|
||||||
|
...lintKeymap,
|
||||||
|
...jumpToDefinitionKeymap,
|
||||||
|
...findReferencesKeymap,
|
||||||
|
...formatKeymap,
|
||||||
|
...renameKeymap,
|
||||||
{ key: "Mod-z", run: () => undo(file.target) },
|
{ key: "Mod-z", run: () => undo(file.target) },
|
||||||
{ key: "Mod-shift-z", run: () => redo(file.target) },
|
{ key: "Mod-shift-z", run: () => redo(file.target) },
|
||||||
{
|
{
|
||||||
|
|
@ -145,7 +158,6 @@ export class Editor extends Displayable {
|
||||||
highlightActiveLineGutter(),
|
highlightActiveLineGutter(),
|
||||||
highlightSelectionMatches(),
|
highlightSelectionMatches(),
|
||||||
indentUnit.of(" "),
|
indentUnit.of(" "),
|
||||||
// lintKeymap,
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -165,9 +177,7 @@ export class Editor extends Displayable {
|
||||||
// Kick off async creation, then reconfigure compartment when ready
|
// Kick off async creation, then reconfigure compartment when ready
|
||||||
createLspExtension(p).then((ext: Extension) => {
|
createLspExtension(p).then((ext: Extension) => {
|
||||||
try {
|
try {
|
||||||
const eff = this.lspCompartment.reconfigure(
|
const eff = this.lspCompartment.reconfigure(ext);
|
||||||
ext as Extension,
|
|
||||||
);
|
|
||||||
this.view.dispatch({ effects: [eff] });
|
this.view.dispatch({ effects: [eff] });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("Failed to apply LSP extension:", err);
|
console.warn("Failed to apply LSP extension:", err);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
import { Extension } from "@codemirror/state";
|
import { Extension } from "@codemirror/state";
|
||||||
|
|
||||||
|
import { LSPClient, languageServerExtensions } from "@codemirror/lsp-client";
|
||||||
|
|
||||||
// Create a very small MessagePort-based transport implementation
|
// Create a very small MessagePort-based transport implementation
|
||||||
// compatible with @codemirror/lsp-client's expected Transport interface.
|
// compatible with @codemirror/lsp-client's expected Transport interface.
|
||||||
async function simpleMessagePortTransport(port: MessagePort) {
|
async function simpleMessagePortTransport(port: MessagePort) {
|
||||||
|
|
@ -15,11 +17,8 @@ async function simpleMessagePortTransport(port: MessagePort) {
|
||||||
};
|
};
|
||||||
port.addEventListener("message", onMessage);
|
port.addEventListener("message", onMessage);
|
||||||
// The port must be started to begin receiving messages
|
// The port must be started to begin receiving messages
|
||||||
try {
|
port.start();
|
||||||
port.start();
|
|
||||||
} catch (err) {
|
|
||||||
// Some environments don't require explicit start()
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
send(message: string) {
|
send(message: string) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -45,7 +44,7 @@ function filePathToUri(path: string) {
|
||||||
const u = new URL("file://" + path);
|
const u = new URL("file://" + path);
|
||||||
return u.toString();
|
return u.toString();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Fallback: naive replacement
|
console.warn("Failed to convert file path to URI via URL:", err);
|
||||||
return "file://" + path;
|
return "file://" + path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -58,24 +57,6 @@ export async function createLspExtension(
|
||||||
): Promise<Extension> {
|
): Promise<Extension> {
|
||||||
if (!filePath) return [];
|
if (!filePath) return [];
|
||||||
|
|
||||||
// Dynamic import so projects without the dependency won't fail at module
|
|
||||||
// load time. This also makes the LSP code optional at runtime.
|
|
||||||
let mod: any;
|
|
||||||
try {
|
|
||||||
// @ts-ignore - the lsp client is optional at runtime; avoid hard
|
|
||||||
// compile-time failures if it's not installed in all environments.
|
|
||||||
mod = await import("@codemirror/lsp-client");
|
|
||||||
} catch (err) {
|
|
||||||
console.warn("@codemirror/lsp-client not available:", err);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const { LSPClient, languageServerExtensions } = mod as any;
|
|
||||||
if (!LSPClient) {
|
|
||||||
console.warn("@codemirror/lsp-client did not export LSPClient");
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to establish a transport via main process MessagePort. This will
|
// Try to establish a transport via main process MessagePort. This will
|
||||||
// cause main to spawn (or reuse) an LSP server and hand us a MessagePort
|
// cause main to spawn (or reuse) an LSP server and hand us a MessagePort
|
||||||
// connected to it.
|
// connected to it.
|
||||||
|
|
@ -121,33 +102,37 @@ export async function createLspExtension(
|
||||||
// directory containing the file.
|
// directory containing the file.
|
||||||
let rootUri: string | undefined = undefined;
|
let rootUri: string | undefined = undefined;
|
||||||
try {
|
try {
|
||||||
const ws = await (window as any).electronAPI.getCurrentWorkspace();
|
const ws = await window.electronAPI.getCurrentWorkspace();
|
||||||
if (ws && ws.root) rootUri = filePathToUri(ws.root);
|
if (ws && ws.root) rootUri = filePathToUri(ws.root);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// ignore and fall back
|
// ignore and fall back
|
||||||
|
console.warn("Failed to get workspace root from main process:", e);
|
||||||
}
|
}
|
||||||
if (!rootUri) {
|
if (!rootUri) {
|
||||||
try {
|
try {
|
||||||
const dir = filePath.replace(/\/[^\/]*$/, "");
|
const dir = filePath.replace(/\/[^\/]*$/, "");
|
||||||
rootUri = filePathToUri(dir);
|
rootUri = filePathToUri(dir);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// ignore
|
console.warn("Failed to convert file path to URI via URL:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new LSPClient({
|
const client = new LSPClient({
|
||||||
extensions: languageServerExtensions(),
|
extensions: languageServerExtensions(),
|
||||||
rootUri: rootUri,
|
rootUri: rootUri,
|
||||||
} as any);
|
});
|
||||||
|
console.log("LSP client created with extensions:", client);
|
||||||
// Pass a client/connection config containing the rootUri. The librar
|
// Pass a client/connection config containing the rootUri. The librar
|
||||||
// accepts a config object; we use `as any` to avoid TS errors here.
|
// accepts a config object; we use `as any` to avoid TS errors here.
|
||||||
const conn = client.connect(transport);
|
client.connect(transport);
|
||||||
|
|
||||||
|
await client.initializing;
|
||||||
|
|
||||||
// The client exposes a `plugin` method which yields an extension that
|
// The client exposes a `plugin` method which yields an extension that
|
||||||
// wires up autocompletion, diagnostics, and other LSP features for a
|
// wires up autocompletion, diagnostics, and other LSP features for a
|
||||||
// given URI. We convert the local path to a file:// URI.
|
// given URI. We convert the local path to a file:// URI.
|
||||||
const uri = filePathToUri(filePath);
|
const uri = filePathToUri(filePath);
|
||||||
return conn.plugin(uri);
|
return client.plugin(uri);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("Failed to create LSP client plugin:", err);
|
console.warn("Failed to create LSP client plugin:", err);
|
||||||
return [];
|
return [];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue