支持全局函数补全
This commit is contained in:
@@ -4,3 +4,4 @@
|
||||
|
||||
- 支持`textMate`语法高亮
|
||||
- 支持`LSP`补全
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Generated
+475
-394
File diff suppressed because it is too large
Load Diff
+4
-7
@@ -20,9 +20,6 @@
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onLanguage:tsl"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"languages": [
|
||||
@@ -58,7 +55,7 @@
|
||||
"tsl.server.arguments": {
|
||||
"type": "array",
|
||||
"default": [
|
||||
"--log=info",
|
||||
"--log=trace",
|
||||
"--log-stderr"
|
||||
],
|
||||
"description": "Arguments for TSL server",
|
||||
@@ -86,11 +83,11 @@
|
||||
"watch": "tsc -watch -p ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.0.3",
|
||||
"@types/node": "^24.5.2",
|
||||
"@types/vscode": "^1.101.0",
|
||||
"@vscode/vsce": "^3.6.0",
|
||||
"prettier": "^3.5.3",
|
||||
"typescript": "^5.8.3"
|
||||
"prettier": "^3.6.2",
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.101.0"
|
||||
|
||||
+84
-51
@@ -1,75 +1,108 @@
|
||||
import * as path from 'path'
|
||||
import * as vscode from 'vscode'
|
||||
import * as fs from 'fs'
|
||||
import {LanguageClient, LanguageClientOptions, ServerOptions, TransportKind} from 'vscode-languageclient/node'
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node'
|
||||
|
||||
let client: LanguageClient
|
||||
|
||||
function findSystemTslServer(): string | null {
|
||||
const binary = process.platform === 'win32' ? 'tsl-server.exe' : 'tsl-server'
|
||||
const pathDirs = process.env.PATH?.split(path.delimiter) || []
|
||||
function findInSystemPath(binary: string): string | null {
|
||||
const pathDirs = process.env.PATH?.split(path.delimiter) || []
|
||||
|
||||
for (const dir of pathDirs) {
|
||||
const fullPath = path.join(dir, binary)
|
||||
if (fs.existsSync(fullPath)) {
|
||||
return fullPath
|
||||
for (const dir of pathDirs) {
|
||||
const fullPath = path.join(dir, binary)
|
||||
if (fs.existsSync(fullPath)) {
|
||||
return fullPath
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
return null
|
||||
function findExecutable(context: vscode.ExtensionContext, configPath: string | undefined, bundledRelativePath: string, systemBinaryName: string): string | null {
|
||||
// 1. 优先使用用户配置的路径
|
||||
if (configPath) {
|
||||
return configPath
|
||||
}
|
||||
|
||||
// 2. 查找插件自带的可执行文件
|
||||
const bundledPath = context.asAbsolutePath(bundledRelativePath)
|
||||
if (fs.existsSync(bundledPath)) {
|
||||
return bundledPath
|
||||
}
|
||||
|
||||
// 3. 从系统 PATH 查找
|
||||
return findInSystemPath(systemBinaryName)
|
||||
}
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// server配置项
|
||||
const config = vscode.workspace.getConfiguration('tsl')
|
||||
const customExecutable = config.get<string>('server.executable', '')
|
||||
const serverArguments = config.get<string[]>('server.arguments')
|
||||
const config = vscode.workspace.getConfiguration('tsl')
|
||||
const serverArguments = config.get<string[]>('server.arguments') || []
|
||||
|
||||
let serverExe: string | null = null
|
||||
|
||||
if (customExecutable) {
|
||||
serverExe = customExecutable
|
||||
} else {
|
||||
const bundledPath = context.asAbsolutePath(
|
||||
path.join('bin', process.platform === 'win32' ? 'tsl-server.exe' : 'tsl-server')
|
||||
const serverBinary = process.platform === 'win32' ? 'tsl-server.exe' : 'tsl-server'
|
||||
let serverExe = findExecutable(
|
||||
context,
|
||||
config.get<string>('server.executable'),
|
||||
path.join('bin', serverBinary),
|
||||
serverBinary
|
||||
)
|
||||
// 查找路径优先级:插件目录 -> 系统 PATH
|
||||
if (fs.existsSync(bundledPath)) {
|
||||
serverExe = bundledPath
|
||||
} else {
|
||||
serverExe = findSystemTslServer()
|
||||
}
|
||||
}
|
||||
|
||||
if (!serverExe) {
|
||||
vscode.window.showErrorMessage(
|
||||
"Cannot find tsl-server. Please install it globally or include it in your extension's server directory."
|
||||
if (!serverExe) {
|
||||
vscode.window.showErrorMessage(
|
||||
"Cannot find tsl-server. Please install it globally or configure 'tsl.server.executable' in settings."
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const interpreterBinary = process.platform === 'win32' ? 'tsl.exe' : 'tsl'
|
||||
let interpreterExe = findExecutable(
|
||||
context,
|
||||
config.get<string>('interpreter.executable'),
|
||||
"",
|
||||
interpreterBinary
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const serverOptions: ServerOptions = {
|
||||
run: {command: serverExe, transport: TransportKind.stdio, args: serverArguments},
|
||||
debug: {command: serverExe, transport: TransportKind.stdio, args: ['--log=trace', '--log-stderr']}
|
||||
}
|
||||
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{scheme: 'file', language: 'tsl'}],
|
||||
synchronize: {
|
||||
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.tsl')
|
||||
if (!interpreterExe) {
|
||||
vscode.window.showWarningMessage(
|
||||
"Cannot find TSL interpreter. Some features may not work. Please install it globally or configure 'tsl.interpreter.executable' in settings."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
client = new LanguageClient(
|
||||
'tslLanguageServer', // 客户端唯一ID
|
||||
'TSL Language Server', // 用户可见名称
|
||||
serverOptions,
|
||||
clientOptions
|
||||
)
|
||||
const runArgs = [...serverArguments]
|
||||
const debugArgs = ['--log=trace', '--log-stderr']
|
||||
|
||||
client.start()
|
||||
if (interpreterExe) {
|
||||
let interpreterDir = path.dirname(interpreterExe)
|
||||
interpreterDir = interpreterDir.replace(/\\/g, '/') + '/'
|
||||
runArgs.push(`--interpreter=${interpreterDir}`)
|
||||
debugArgs.push(`--interpreter=${interpreterDir}`)
|
||||
}
|
||||
|
||||
const serverOptions: ServerOptions = {
|
||||
run: { command: serverExe, transport: TransportKind.stdio, args: runArgs },
|
||||
debug: { command: serverExe, transport: TransportKind.stdio, args: debugArgs }
|
||||
}
|
||||
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ scheme: 'file', language: 'tsl' }],
|
||||
synchronize: {
|
||||
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.tsl')
|
||||
}
|
||||
}
|
||||
|
||||
client = new LanguageClient(
|
||||
'tslLanguageServer',
|
||||
'TSL Language Server',
|
||||
serverOptions,
|
||||
clientOptions
|
||||
)
|
||||
|
||||
// 保存解释器路径到上下文,供其他命令使用
|
||||
if (interpreterExe) {
|
||||
context.globalState.update('tsl.interpreterPath', interpreterExe)
|
||||
}
|
||||
|
||||
client.start()
|
||||
}
|
||||
|
||||
export function deactivate(): Thenable<void> | undefined {
|
||||
return client ? client.stop() : undefined
|
||||
return client ? client.stop() : undefined
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user