Skip to content

Commit

Permalink
feat: load TS typings for monaco editor
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed May 31, 2024
1 parent 372ba58 commit 6a94d87
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
22 changes: 15 additions & 7 deletions components/CodeEditor.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { AutoTypings, LocalStorageCache } from 'monaco-editor-auto-typings'
import type { MonacoLanguage } from '#imports'
import type * as Monaco from 'monaco-editor'
import type { MonacoEditor } from '#build/components'
Expand All @@ -20,13 +21,20 @@ const options = computed<Monaco.editor.IStandaloneEditorConstructionOptions>(
)
if (props.input) {
watchEffect(() => {
const editor = toRaw(container.value?.$editor)
if (!editor) return
editor.onDidChangeCursorPosition((e) => {
editorCursor.value = editor.getModel()!.getOffsetAt(e.position)
})
})
watch(
() => container.value?.$editor,
(editor) => {
if (!editor) return
editor.onDidChangeCursorPosition((e) => {
editorCursor.value = editor.getModel()!.getOffsetAt(e.position)
})
AutoTypings.create(editor, {
sourceCache: new LocalStorageCache(),
})
},
{ immediate: true },
)
let decorationsCollection:
| Monaco.editor.IEditorDecorationsCollection
Expand Down
5 changes: 5 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export default defineNuxtConfig({
esbuild: {
legalComments: 'external',
},
resolve: {
alias: {
path: 'pathe',
},
},
},
devtools: {
enabled: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"fflate": "^0.8.2",
"json-to-ast": "^2.1.0",
"json5": "^2.2.3",
"monaco-editor": "^0.49.0"
"monaco-editor": "^0.49.0",
"monaco-editor-auto-typings": "^0.4.5"
},
"devDependencies": {
"@babel/parser": "^7.24.6",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 6a94d87

Please sign in to comment.