Skip to content

Commit

Permalink
fix: debounce reloadLanguageTools in monaco
Browse files Browse the repository at this point in the history
closes #275 closes #263
  • Loading branch information
sxzz committed Aug 27, 2024
1 parent 00176d0 commit f9f650a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/monaco/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { CreateData } from './vue.worker'
import vueWorker from './vue.worker?worker'
import * as languageConfigs from './language-configs'
import type { LanguageService } from '@vue/language-service'
import { debounce } from '../utils'

let initted = false
export function initMonaco(store: Store) {
Expand Down Expand Up @@ -155,7 +156,12 @@ export function loadMonacoEnv(store: Store) {
languages.setLanguageConfiguration('typescript', languageConfigs.ts)
languages.setLanguageConfiguration('css', languageConfigs.css)

store.reloadLanguageTools = () => reloadLanguageTools(store)
let languageToolsPromise: Promise<void> | undefined
store.reloadLanguageTools = debounce(async () => {
;(languageToolsPromise ||= reloadLanguageTools(store)).finally(() => {
languageToolsPromise = undefined
})
}, 250)
languages.onLanguage('vue', () => store.reloadLanguageTools!())

// Support for go to definition
Expand Down

0 comments on commit f9f650a

Please sign in to comment.