Skip to content

Commit

Permalink
Added auto typing
Browse files Browse the repository at this point in the history
  • Loading branch information
notangelmario committed Mar 19, 2023
1 parent 70f022f commit 39c3cc0
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
40 changes: 33 additions & 7 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "marker",
"private": true,
"author": "Savin Angel-Mario ([email protected])",
"version": "1.2.8",
"version": "1.3.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -21,6 +21,8 @@
},
"dependencies": {
"marked": "^4.1.1",
"monaco-editor": "^0.34.0"
"monaco-editor": "^0.34.0",
"monaco-editor-auto-typings": "^0.4.3",
"path-browserify": "^1.0.1"
}
}
4 changes: 2 additions & 2 deletions src/lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export async function setEditorText(editor: monaco.editor.IStandaloneCodeEditor,
const ext = getExtension(file.name);

monaco.editor.getModels().forEach((model) => model.dispose());
editor.setModel(monaco.editor.createModel(await file.text(), fileTypes.get(ext), monaco.Uri.file(file.name)));
editor.setModel(monaco.editor.createModel(await file.text(), fileTypes.get(ext)/*, monaco.Uri.file(file.name)*/));

setTimeout(() => {
editor.focus();
}, 100);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/languages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker'
//@ts-ignore
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'

export { initAutoTypings } from "./typescript";

// MonacoEnvironment should be initialized before the editor
export function initLanguageWorkers() {
self.MonacoEnvironment = {
Expand All @@ -28,4 +30,4 @@ export function initLanguageWorkers() {
return new editorWorker()
}
}
}
}
9 changes: 9 additions & 0 deletions src/lib/languages/typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import monaco from "monaco-editor";
import { AutoTypings, LocalStorageCache } from "monaco-editor-auto-typings";

export function initAutoTypings(editor: monaco.editor.IStandaloneCodeEditor) {
console.log("initAutoTypings");
AutoTypings.create(editor, {
sourceCache: new LocalStorageCache(),
});
}
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { registerSW } from 'virtual:pwa-register'
import { initStore } from "./lib/store";
import { initEditor } from "./lib/editor";
import { closeModal, openModal } from "./lib/modal";
import { initLanguageWorkers } from "./lib/languages";
import { initAutoTypings, initLanguageWorkers } from "./lib/languages";
import { createNotice, initStatus } from "./lib/status";
import { isCompat } from "./lib/compat";

Expand All @@ -14,6 +14,7 @@ if (isCompat) {
initLanguageWorkers();
const editor = initEditor(editorWrapper, store);
initStatus(editor);
initAutoTypings(editor);

window.onbeforeunload = () => {
if (editor.getValue() !== "") {
Expand Down
7 changes: 6 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export default defineConfig({
}
}),
],
resolve: {
alias: {
path: "path-browserify"
}
},
build: {
outDir: resolve(__dirname, "dist"),
emptyOutDir: true,
Expand All @@ -37,4 +42,4 @@ export default defineConfig({
}
}
}
});
});

0 comments on commit 39c3cc0

Please sign in to comment.