Skip to content

Commit c51f634

Browse files
joe-ptristanmenzel
authored andcommitted
feat: LSP serverInfo
Also includes a small refactor to app-version to make it easier to get just the package version
1 parent 253c1b9 commit c51f634

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/cli/app-version.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@ import { fileURLToPath } from 'node:url'
33
import pathe from 'pathe'
44
import { Constants } from '../constants'
55

6-
export function appVersion(options?: { name?: string; withAVMVersion?: boolean }): string {
6+
export function packageVersion(): string {
77
let dirName = pathe.dirname(fileURLToPath(import.meta.url))
8-
const name = options?.name ?? 'puya-ts'
9-
const withAVMVersion = options?.withAVMVersion ?? true
108

119
while (true) {
1210
const packageJsonPath = pathe.join(dirName, 'package.json')
1311
if (fs.existsSync(packageJsonPath)) {
14-
const version = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version
15-
return [`${name} ${version}`]
16-
.concat(
17-
withAVMVersion
18-
? ['', 'Targets:', `puya ${Constants.targetedPuyaVersion}`, `AVM ${Constants.supportedAvmVersions.join(', ')}`]
19-
: [`puya ${Constants.targetedPuyaVersion}`],
20-
)
21-
.join('\r\n')
12+
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version
2213
}
2314
if (dirName === pathe.dirname(dirName)) break
2415
dirName = pathe.dirname(dirName)
2516
}
26-
return `Cannot determine puya-ts version`
17+
return 'unknown'
18+
}
19+
20+
export function appVersion(options?: { name?: string; withAVMVersion?: boolean }): string {
21+
const name = options?.name ?? 'puya-ts'
22+
const withAVMVersion = options?.withAVMVersion ?? true
23+
24+
const version = packageVersion()
25+
return [`${name} ${version}`]
26+
.concat(
27+
withAVMVersion
28+
? ['', 'Targets:', `puya ${Constants.targetedPuyaVersion}`, `AVM ${Constants.supportedAvmVersions.join(', ')}`]
29+
: [`puya ${Constants.targetedPuyaVersion}`],
30+
)
31+
.join('\n')
2732
}

src/language-server/puya-language-server.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TextDocument } from 'vscode-languageserver-textdocument'
22
import * as lsp from 'vscode-languageserver/node'
3-
import { appVersion } from '../cli/app-version'
3+
import { appVersion, packageVersion } from '../cli/app-version'
44
import { Constants } from '../constants'
55
import { logger, LogLevel } from '../logger'
66
import { LanguageServerLogSink } from '../logger/sinks/language-server-log-sink'
@@ -40,6 +40,8 @@ export type LanguageServerOptions = {
4040
customPuyaPath?: string
4141
}
4242

43+
const PACKAGE_VERSION = packageVersion()
44+
4345
export class PuyaLanguageServer {
4446
readonly documents = new lsp.TextDocuments(TextDocument)
4547
readonly triggers = new CompileTriggerQueue()
@@ -85,6 +87,10 @@ export class PuyaLanguageServer {
8587
workspaces: this.workspaceFolders,
8688
})
8789
return {
90+
serverInfo: {
91+
name: 'Puya-TS Language Server',
92+
version: PACKAGE_VERSION,
93+
},
8894
capabilities: {
8995
textDocumentSync: lsp.TextDocumentSyncKind.Incremental,
9096
codeActionProvider: {

0 commit comments

Comments
 (0)