8000 feat(lang-service): support track virtual code generation by ShenQingchuan · Pull Request #284 · vue-vine/vue-vine · GitHub
[go: up one dir, main page]

Skip to content

feat(lang-service): support track virtual code generation #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions 8000 packages/language-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { create as createTypeScriptServices } from 'volar-service-typescript'
import { createVineDiagnosticsPlugin } from './plugins/vine-diagnostics'
import { createVineFoldingRangesPlugin } from './plugins/vine-folding-ranges'
import { createVineTemplatePlugin } from './plugins/vine-template'
import { track } from './track'

const connection = createConnection()
const server = createServer(connection)
Expand Down Expand Up @@ -86,6 +87,7 @@ connection.onInitialize(async (params) => {
compilerOptions,
vueCompilerOptions,
target: 'extension',
track,
},
),
]
Expand Down
24 changes: 24 additions & 0 deletions packages/language-server/src/track.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { TrackOutputChannel } from '@vue-vine/language-service'
import { env } from 'node:process'
import { Track } from '@vue-vine/language-service'

const {
vscodeVersion = 'unknown',
extensionVersion = 'unknown',
machineId = 'unknown',
isTrackDisabled = 'false',
} = env

const outputChannel: TrackOutputChannel = {
appendLine: (message) => {
console.log(message)
},
}

export const track: Track = new Track({
isTrackDisabled: isTrackDisabled === 'true',
vscodeVersion,
extensionVersion,
machineId,
outputChannel,
})
1 change: 1 addition & 0 deletions packages/language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"typecheck": "tsgo --noEmit"
},
"dependencies": {
"@umami/node": "catalog:miscs",
"@volar/language-core": "catalog:volar",
"@volar/language-server": "catalog:volar",
"@volar/typescript": "catalog:volar",
Expand Down
12 changes: 12 additions & 0 deletions packages/language-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
VueCompilerOptions,
} from '@vue/language-core'
import type * as ts from 'typescript'
import type { Track } from './track'
import {
forEachEmbeddedCode,
} from '@volar/language-core'
Expand Down Expand Up @@ -33,6 +34,14 @@ export type {
VueVineVirtualCode,
} from './shared'

export {
getLogTimeLabel,
Track,
} from './track'
export type {
TrackOutputChannel,
} from './track'

export {
createVueVineVirtualCode,
} from './virtual-code'
Expand All @@ -41,6 +50,7 @@ interface VineLanguagePluginOptions {
compilerOptions: ts.CompilerOptions
vueCompilerOptions: VueCompilerOptions
target?: 'extension' | 'tsc'
track?: Track
}

export function createVueVineLanguagePlugin(
Expand All @@ -50,6 +60,7 @@ export function createVueVineLanguagePlugin(
const {
compilerOptions,
vueCompilerOptions,
track,
target = 'extension',
} = options

Expand Down Expand Up @@ -84,6 +95,7 @@ export function createVueVineLanguagePlugin(
vueCompilerOptions,
target,
)
track?.trackEvent('virtual_code_created')
return virtualCode
}
catch (err) {
Expand Down
92 changes: 92 additions & 0 deletions packages/language-service/src/track.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Umami } from '@umami/node'

export type TrackEvent
= | 'extension_activated'
| 'restart_server'
| 'virtual_code_created'

const logFormat = new Intl.DateTimeFormat('zh-CN', {
hour12: false,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
})
export function getLogTimeLabel(): string {
// Format: `2025-06-18 10:00:00`
return logFormat.format(new Date())
}

export interface TrackOutputChannel {
appendLine: (message: string) => void
}

export class Track {
private _isDisabled: boolean = false
private _vscodeVersion: string
private _extensionVersion: string
private _machineId: string
private _websiteId: string
private _hostUrl: string
private _client: Umami
private _outputChannel: TrackOutputChannel

constructor({
isTrackDisabled,
vscodeVersion,
extensionVersion,
machineId,
outputChannel,
}: {
isTrackDisabled: boolean
vscodeVersion: string
extensionVersion: string
machineId: string
outputChannel: TrackOutputChannel
}) {
this._websiteId = 'dc82842c-bd27-4bdd-8305-2f5558695020'
this._hostUrl = 'https://stats.dokduk.cc'
this._isDisabled = isTrackDisabled
this._vscodeVersion = vscodeVersion
this._extensionVersion = extensionVersion
this._machineId = machineId
this._outputChannel = outputChannel
this._client = new Umami({
websiteId: this._websiteId,
hostUrl: this._hostUrl,
sessionId: this._machineId,
})
}

public async trackEvent(
event: TrackEvent,
): Promise<void> {
if (this._isDisabled)
return

try {
await this._client.send({
website: this._websiteId,
name: event,
data: {
vscodeVersion: this._vscodeVersion,
extensionVersion: this._extensionVersion,
machineId: this._machineId,
},
}, 'event')
this._outputChannel.appendLine(`${getLogTimeLabel()} - '${event}' event has been sent`)
}
catch (error) {
this._outputChannel.appendLine(`${getLogTimeLabel()} - '${event}' track failed: ${error}`)
}
}

public toggleDisabled(isDisabled: boolean): void {
this._isDisabled = isDisabled
}

public disable(): void {
this._isDisabled = true
}
}
1 change: 0 additions & 1 deletion packages/vscode-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
"@changesets/changelog-github": "catalog:utils",
"@types/vscode": "catalog:types",
"@typescript/native-preview": "catalog:compiler",
"@umami/node": "catalog:miscs",
"@volar/vscode": "catalog:volar",
"@vscode/vsce": "catalog:vscode",
"@vue-vine/language-server": "workspace:*",
Expand Down
60 changes: 34 additions & 26 deletions packages/vscode-ext/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import type {
LabsInfo,
} from '@volar/vscode'
import {
activateAutoInsertion,
createLabsInfo,
getTsdk,
} from '@volar/vscode'
import type { LabsInfo } from '@volar/vscode'
import type { Track } from '@vue-vine/language-service'
import { activateAutoInsertion, createLabsInfo, getTsdk } from '@volar/vscode'
import * as lsp from '@volar/vscode/node'
import { useOutputChannel } from 'reactive-vscode'
import { getLogTimeLabel } from '@vue-vine/language-service'
import * as vscode from 'vscode'
import { useExtensionConfigs } from './config'
import { Track } from './track'
import { useDataTrackWarning, useVineExtensionViewFeatures } from './view-features'
import { useDataTrack } from './track'
import { useVineExtensionViewFeatures } from './view-features'

let client: lsp.BaseLanguageClient
let track: Track

export async function activate(context: vscode.ExtensionContext): Promise<LabsInfo> {
const extensionConfigs = useExtensionConfigs()
const envInfo = {
vscodeVersion: vscode.version,
extensionVersion: context.extension.packageJSON.version,
machineId: vscode.env.machineId,
isTrackDisabled: !extensionConfigs.dataTrack.value,
}

const serverModule = vscode.Uri.joinPath(context.extensionUri, 'dist', 'server.js')
const runOptions = { execArgv: <string[]>[] }
const debugOptions = { execArgv: ['--nolazy', `--inspect=6019`] }
const runOptions: lsp.ForkOptions = {
execArgv: [] as string[],
env: { ...envInfo },
}
const debugOptions: lsp.ForkOptions = {
execArgv: ['--nolazy', `--inspect=6019`],
env: { ...envInfo },
}
const serverOptions: lsp.ServerOptions = {
run: {
module: serverModule.fsPath,
Expand All @@ -41,37 +50,36 @@ export async function activate(context: vscode.ExtensionContext): Promise<LabsIn
documentSelector: [{ language: 'typescript' }],
initializationOptions,
}
const outputChannelName = 'Vine Language Server'
const outputChannelName = 'Vue Vine Extension'
client = new lsp.LanguageClient(
'vine-language-server',
outputChannelName,
serverOptions,
clientOptions,
)

const outputChannel = useOutputChannel('Vue Vine Extension')

outputChannel.appendLine('Starting Vine Language Server ...')
const outputChannel = client.outputChannel
outputChannel.appendLine(`${getLogTimeLabel()} - Starting Vine Language Server ...`)

await client.start()
outputChannel.appendLine('Vine language server started')
outputChannel.appendLine(`${getLogTimeLabel()} - Vine language server started`)

// support for auto close tag
activateAutoInsertion(['typescript'], client)

const labsInfo = createLabsInfo()
labsInfo.addLanguageClient(client)

// Start track
const extensionConfigs = useExtensionConfigs()
useDataTrackWarning(extensionConfigs)
track = new Track({
track = await useDataTrack(
extensionConfigs,
vscodeVersion: vscode.version,
extensionVersion: context.extension.packageJSON.version,
machineId: vscode.env.machineId,
outputChannel,
})
envInfo,
)
outputChannel.appendLine(`${getLogTimeLabel()} - Track setup:\n${[
` - vscodeVersion: ${envInfo.vscodeVersion}`,
` - extensionVersion: ${envInfo.extensionVersion}`,
` - machineId: ${envInfo.machineId}`,
].join('\n')}`)
await track.trackEvent('extension_activated')

useVineExtensionViewFeatures(client, track)
Expand Down
Loading
Loading
0