Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions extensions/vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import type { GetPackageManagerRequest } from '#shared/protocol'
import type { DocumentFilter } from '@volar/vscode'
import { displayName, extensionId } from '#shared/meta'
import { GET_PACKAGE_MANAGER_METHOD } from '#shared/protocol'
import { logger } from '#state'
import { SUPPORTED_DOCUMENT_PATTERN } from '#utils/constants'
import { middleware } from '@volar/vscode'
import { LanguageClient, TransportKind } from '@volar/vscode/node'
import { commands, Uri } from 'vscode'
import { commands, Hover, MarkdownString, Uri } from 'vscode'

const SUPPORTED_LANGUAGES = [
'javascript',
Expand All @@ -20,6 +19,10 @@ const SUPPORTED_LANGUAGES = [
'html',
] as const

function transformMarkdownString(md: string) {
return new MarkdownString(md, true)
}
Comment thread
9romise marked this conversation as resolved.

export function launch(serverPath: string) {
const client = new LanguageClient(
extensionId,
Expand All @@ -36,7 +39,28 @@ export function launch(serverPath: string) {
},
},
{
middleware,
middleware: {
...middleware,
provideHover: async (document, position, token, next) => {
const hover = await next(document, position, token)
if (!hover)
return

const contents = hover.contents.map((c) => {
if (typeof c === 'string') {
return transformMarkdownString(c)
}

if ('value' in c) {
return transformMarkdownString(c.value)
}

return c
})

return new Hover(contents, hover.range)
},
},
documentSelector: [
{ scheme: 'file', pattern: SUPPORTED_DOCUMENT_PATTERN },
...SUPPORTED_LANGUAGES.map((language) => ({ scheme: 'file', language } satisfies DocumentFilter)),
Expand All @@ -45,7 +69,11 @@ export function launch(serverPath: string) {
isTrusted: true,
supportHtml: true,
},
outputChannel: logger.logger.value!,
synchronize: {
configurationSection: [displayName],
},
diagnosticCollectionName: displayName,
outputChannelName: `${displayName} Language Server`,
},
)

Expand Down
20 changes: 8 additions & 12 deletions extensions/vscode/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useWorkspaceContext } from '#composables/workspace-context'
import { commands, displayName, version } from '#shared/meta'
// TODO: Uncomment when language server integration is ready
// import { createLabsInfo } from '@volar/vscode'
import { createLabsInfo } from '@volar/vscode'
import { defineExtension, useCommands } from 'reactive-vscode'
// import { Uri } from 'vscode'
// import { launch } from './client'
import { Uri } from 'vscode'
import { launch } from './client'
import { openFileInNpmx } from './commands/open-file-in-npmx'
import { openInBrowser } from './commands/open-in-browser'
import { useCodeActions } from './providers/code-actions'
Expand All @@ -13,20 +12,17 @@ import { useDecorators } from './providers/decorators'
import { useDefinition } from './providers/definition'
import { useDiagnostics } from './providers/diagnostics'
import { useDocumentLink } from './providers/document-link'
import { useHover } from './providers/hover'
import { logger } from './state'

export const { activate, deactivate } = defineExtension((_ctx) => {
// TODO: Uncomment when language server integration is ready
// const volarLabs = createLabsInfo()
export const { activate, deactivate } = defineExtension((ctx) => {
const volarLabs = createLabsInfo()

// const serverPath = Uri.joinPath(ctx.extensionUri, './dist/server/bin/index.js').fsPath
// const { client } = launch(serverPath)
// volarLabs.addLanguageClient(client)
const serverPath = Uri.joinPath(ctx.extensionUri, './dist/server/bin/index.js').fsPath
const { client } = launch(serverPath)
volarLabs.addLanguageClient(client)

useWorkspaceContext()

useHover()
useCompletionItem()
useDiagnostics()
useDecorators()
Expand Down
31 changes: 0 additions & 31 deletions extensions/vscode/src/providers/hover/index.ts

This file was deleted.

54 changes: 0 additions & 54 deletions extensions/vscode/src/providers/hover/npmx.ts

This file was deleted.

Loading
Loading