2024-07-03 22:06:52 -07:00
|
|
|
import { foldService } from '@codemirror/language'
|
2025-04-01 23:54:26 -07:00
|
|
|
import type { EditorState, Extension } from '@codemirror/state'
|
2024-06-30 14:30:44 -07:00
|
|
|
import { ViewPlugin } from '@codemirror/view'
|
|
|
|
|
2025-04-01 23:54:26 -07:00
|
|
|
import type { LanguageServerOptions } from './plugin/lsp'
|
2024-06-30 14:30:44 -07:00
|
|
|
import {
|
|
|
|
LanguageServerPlugin,
|
|
|
|
LanguageServerPluginSpec,
|
2025-04-01 23:54:26 -07:00
|
|
|
docPathFacet,
|
2024-06-30 14:30:44 -07:00
|
|
|
languageId,
|
|
|
|
workspaceFolders,
|
|
|
|
} from './plugin/lsp'
|
|
|
|
|
|
|
|
export { LanguageServerClient } from './client'
|
2025-04-01 23:54:26 -07:00
|
|
|
export type { LanguageServerClientOptions } from './client'
|
|
|
|
export { FromServer, IntoServer, LspWorkerEventType } from './client/codec'
|
|
|
|
export { Codec } from './client/codec/utils'
|
2024-06-30 14:30:44 -07:00
|
|
|
export {
|
2025-04-01 23:54:26 -07:00
|
|
|
lspDiagnosticsEvent,
|
|
|
|
lspFormatCodeEvent,
|
2025-04-29 17:57:02 -07:00
|
|
|
lspRenameEvent,
|
2025-04-01 23:54:26 -07:00
|
|
|
lspSemanticTokensEvent,
|
2025-04-29 17:57:02 -07:00
|
|
|
lspCodeActionEvent,
|
2025-04-01 23:54:26 -07:00
|
|
|
} from './plugin/annotation'
|
2024-06-30 14:30:44 -07:00
|
|
|
export {
|
|
|
|
LanguageServerPlugin,
|
|
|
|
LanguageServerPluginSpec,
|
|
|
|
docPathFacet,
|
|
|
|
languageId,
|
|
|
|
workspaceFolders,
|
|
|
|
} from './plugin/lsp'
|
2025-04-01 23:54:26 -07:00
|
|
|
export type { LanguageServerOptions } from './plugin/lsp'
|
|
|
|
export { offsetToPos, posToOffset } from './plugin/util'
|
2024-06-30 14:30:44 -07:00
|
|
|
|
|
|
|
export function lspPlugin(options: LanguageServerOptions): Extension {
|
|
|
|
let plugin: LanguageServerPlugin | null = null
|
|
|
|
const viewPlugin = ViewPlugin.define(
|
|
|
|
(view) => (plugin = new LanguageServerPlugin(options, view)),
|
|
|
|
new LanguageServerPluginSpec()
|
|
|
|
)
|
|
|
|
|
|
|
|
let ext = [
|
|
|
|
docPathFacet.of(options.documentUri),
|
|
|
|
languageId.of('kcl'),
|
|
|
|
workspaceFolders.of(options.workspaceFolders),
|
|
|
|
viewPlugin,
|
|
|
|
foldService.of((state: EditorState, lineStart: number, lineEnd: number) => {
|
|
|
|
if (plugin == null) return null
|
|
|
|
// Get the folding ranges from the language server.
|
|
|
|
// Since this is async we directly need to update the folding ranges after.
|
2024-07-03 21:28:51 -07:00
|
|
|
const range = plugin?.foldingRange(lineStart, lineEnd)
|
|
|
|
return range
|
2024-06-30 14:30:44 -07:00
|
|
|
}),
|
|
|
|
]
|
|
|
|
|
|
|
|
return ext
|
|
|
|
}
|