Skip to content

Commit

Permalink
feat: register language configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Feb 10, 2024
1 parent d3ee13d commit 3ad7035
Show file tree
Hide file tree
Showing 2 changed files with 555 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/monaco/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Store } from '../store'
import { getOrCreateModel } from './utils'
import type { CreateData } from './vue.worker'
import vueWorker from './vue.worker?worker'
import * as languageConfigs from './language-configs'

let initted = false
export function initMonaco(store: Store) {
Expand Down Expand Up @@ -36,26 +37,6 @@ export function initMonaco(store: Store) {
}
})

// Support for go to definition
editor.registerEditorOpener({
openCodeEditor(_, resource) {
if (resource.toString().startsWith(jsDelivrUriBase + '/')) {
return true
}

const path = resource.path
if (/^\//.test(path)) {
const fileName = path.replace('/', '')
if (fileName !== store.activeFile.filename) {
store.setActive(fileName)
return true
}
}

return false
},
})

initted = true
}

Expand Down Expand Up @@ -166,7 +147,32 @@ export function loadMonacoEnv(store: Store) {
languages.register({ id: 'vue', extensions: ['.vue'] })
languages.register({ id: 'javascript', extensions: ['.js'] })
languages.register({ id: 'typescript', extensions: ['.ts'] })
languages.register({ id: 'css', extensions: ['.css'] })
languages.setLanguageConfiguration('vue', languageConfigs.vue)
languages.setLanguageConfiguration('javascript', languageConfigs.js)
languages.setLanguageConfiguration('typescript', languageConfigs.ts)
languages.setLanguageConfiguration('css', languageConfigs.css)

store.reloadLanguageTools = () => reloadLanguageTools(store)
languages.onLanguage('vue', () => store.reloadLanguageTools!())

// Support for go to definition
editor.registerEditorOpener({
openCodeEditor(_, resource) {
if (resource.toString().startsWith(jsDelivrUriBase + '/')) {
return true
}

const path = resource.path
if (/^\//.test(path)) {
const fileName = path.replace('/', '')
if (fileName !== store.activeFile.filename) {
store.setActive(fileName)
return true
}
}

return false
},
})
}
Loading

0 comments on commit 3ad7035

Please sign in to comment.