Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/lib/editorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ import quickTools from "components/quickTools";
import ScrollBar from "components/scrollbar";
import SideButton, { sideButtonContainer } from "components/sideButton";
import keyboardHandler, { keydownState } from "handlers/keyboard";
import {
createSnippetCompletionSource,
expandSnippetShortcut,
} from "lib/snippets";
import EditorFile from "./editorFile";
import openFile from "./openFile";
import { addedFolder } from "./openFolder";
Expand Down Expand Up @@ -1155,6 +1159,24 @@ async function EditorManager($header, $body) {
});
const exts = [...baseExtensions];
maybeAttachEmmetCompletions(exts, syntax);
const snippetLanguageId = getFileLanguageId(file);
exts.push(
EditorState.languageData.of(() => [
{
autocomplete: createSnippetCompletionSource(snippetLanguageId),
},
]),
);
exts.push(
Prec.high(
keymap.of([
{
key: "Tab",
run: (view) => expandSnippetShortcut(view, snippetLanguageId),
},
]),
),
);
Comment on lines +1162 to +1179
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Language ID is captured once per file-open, not per language switch

snippetLanguageId is evaluated once in applyFileToEditor and then closed over in both the completion source and the Tab keymap. If the user later changes the file's language (mode) without re-opening the file, the snippet engine will keep using the stale language ID. The existing languageCompartment.reconfigure() path won't update these closures. Consider deriving the language ID dynamically from the view's state inside both callbacks instead.

try {
const langExtFn = file.currentLanguageExtension;
let initialLang = [];
Expand Down
4 changes: 4 additions & 0 deletions src/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ class Settings {
servers: {},
},
developerMode: false,
snippets: {
enabled: true,
user: {},
},
shiftClickSelection: false,
};
this.value = structuredClone(this.#defaultSettings);
Expand Down
Loading