Skip to content

Commit

Permalink
fix: resolve async issues with language tools loading
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylost committed Aug 24, 2024
1 parent 802b0f8 commit ea7a055
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/monaco/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class WorkerHost {
}
}

let resolveLanguageToolsLoaded: () => void
let isLanguageToolsLoaded: Promise<void>
let disposeVue: undefined | (() => void)
export async function reloadLanguageTools(store: Store) {
disposeVue?.()
Expand Down Expand Up @@ -115,6 +117,7 @@ export async function reloadLanguageTools(store: Store) {
disposeAutoInsertion()
disposeProvides()
}
resolveLanguageToolsLoaded?.()
}

export interface WorkerMessage {
Expand Down Expand Up @@ -155,7 +158,17 @@ export function loadMonacoEnv(store: Store) {
languages.setLanguageConfiguration('typescript', languageConfigs.ts)
languages.setLanguageConfiguration('css', languageConfigs.css)

store.reloadLanguageTools = () => reloadLanguageTools(store)
store.reloadLanguageTools = async () => {
if (!isLanguageToolsLoaded) {
isLanguageToolsLoaded = new Promise((resolve) => {
resolveLanguageToolsLoaded = resolve
})
} else {
await isLanguageToolsLoaded
isLanguageToolsLoaded = null
}
return reloadLanguageTools(store)
}
languages.onLanguage('vue', () => store.reloadLanguageTools!())

// Support for go to definition
Expand Down

0 comments on commit ea7a055

Please sign in to comment.