Skip to content

Commit

Permalink
new language server
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Mar 31, 2024
1 parent f9b5abe commit 56e4271
Show file tree
Hide file tree
Showing 15 changed files with 2,163 additions and 204 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- uses: actions/checkout@master
- name: Set node 16.x
- name: Set node 20.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
- name: Install
uses: borales/actions-yarn@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"${workspaceFolder}/out/**/*.js"
],
"env": {
"EMMY_DEV": "true"
"EMMY_DEV": "false"
},
"preLaunchTask": "npm: watch"
},
Expand Down
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@

[English Change Log](CHANGELOG_EN.md)

## next
## 0.6.0

`NEW` 可选的使用新的语言分析后端,新的分析后端支持更多的特性,包括但不限于:
- 真泛型类
- 复杂泛型函数的类型推断
- 运算符重载
- 多重继承
- 接口和接口继承
- enum和alias的常量补全
- 支持元组类型 [int, int, int]
- 支持---@async标注
- Emmylua doc可以在任意处换行, 并且支持多行注释
- 支持 #123456 格式的文本的color显示
- 支持基于代码补全的auto require (如果模块存在返回值)
- 调整require的路径显示
- 兼容LuaLs的大部分doc标注, 但功能并未完全实现

`NOTE` java版本的语言服务会和C#写的语言服务共存, 去settings下搜索emmylua.new开启后重启vscode即可, 版本号暂时升级到0.6, 经过1到2个月的BUG修复期之后, 版本会升级到0.7, 此时会移除java版本的语言服务.
再经过一段时间的稳定, vscode-emmylua版本号将升级到1.0

新语言服务的地址: https://github.com/CppCXY/EmmyLuaAnalyzer

全新的语言服务正在开发中, 项目使用C#重写.

## 0.5.19

Expand Down
26 changes: 22 additions & 4 deletions CHANGELOG_EN.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# Change Log


## next

A completely new language service is under development, and the project is rewritten using C#.
## 0.6.0

`NEW` Optional use of the new language analysis backend, the new analysis backend supports more features, including but not limited to:
- True generic classes
- Complex generic function type inference
- Operator overloading
- Multiple inheritance
- Interface inheritance
- Constant completion of enum and alias
- Support for tuple types [int, int, int]
- Support for ---@async annotation
- Emmylua doc can be line-wrapped anywhere, and supports multi-line comments
- Support for color display of #123456 format text
- Support for auto require based on code completion (module has return value)
- Adjust the display of require path
- Compatible with most of LuaLs's doc annotations, but the function is not fully implemented

`NOTE` The Java version of the language service can coexist with the language service written in C#. To enable it, search for "emmylua.new" in settings, restart vscode after enabling. The version number is currently upgraded to 0.6. After 1 to 2 months of bug fixing, the version will be upgraded to 0.7, at which point the Java version of the language service will be removed. After a period of stability, the vscode-emmylua version number will be upgraded to 1.0.

The address of the new language service: https://github.com/CppCXY/EmmyLuaAnalyzer

`NEW` The debugger provides stronger customization features

## 0.5.19

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

VSCode version of [EmmyLua](https://github.com/EmmyLua/IntelliJ-EmmyLua)

[![Build status](https://ci.appveyor.com/api/projects/status/5psq8f7jjix23mwg?svg=true)](https://ci.appveyor.com/project/EmmyLua/vscode-emmylua)

QQ交流群:`29850775` (最新版本以及部分视频演示在群文件中下载)

Expand Down Expand Up @@ -47,4 +46,4 @@ A: 在项目根目录创建`emmy.config.json`然后如下填写:
```
Q: 全新的语言服务何时上线?

A: 不知道
A: 现在已经上线, 去settings下搜索emmylua.new开启后重启vscode即可
4 changes: 3 additions & 1 deletion build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ exports.default = {
emmyDebuggerVersion: '1.7.1',
emmyDebuggerUrl: 'https://github.com/EmmyLua/EmmyLuaDebugger/releases/download',
lanServerVersion: "0.5.16",
lanServerUrl: 'https://github.com/EmmyLua/EmmyLua-LanguageServer/releases/download'
lanServerUrl: 'https://github.com/EmmyLua/EmmyLua-LanguageServer/releases/download',
newLanguageServerVersion: "0.1.0",
newLanguageServerUrl: "https://github.com/CppCXY/EmmyLuaAnalyzer/releases/download"
}
9 changes: 9 additions & 0 deletions build/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ async function downloadDepends() {
downloadTo(`${config.emmyDebuggerUrl}/${config.emmyDebuggerVersion}/win32-x86.zip`, 'temp/win32-x86.zip'),
downloadTo(`${config.emmyDebuggerUrl}/${config.emmyDebuggerVersion}/win32-x64.zip`, 'temp/win32-x64.zip'),
downloadTo(`${config.lanServerUrl}/${config.lanServerVersion}/EmmyLua-LS-all.jar`, 'temp/EmmyLua-LS-all.jar'),
downloadTo(`${config.newLanguageServerUrl}/${config.newLanguageServerVersion}/linux-x64.zip`, 'temp/server-linux-x64.zip'),
downloadTo(`${config.newLanguageServerUrl}/${config.newLanguageServerVersion}/darwin-arm64.zip`, 'temp/server-darwin-arm64.zip'),
downloadTo(`${config.newLanguageServerUrl}/${config.newLanguageServerVersion}/darwin-x64.zip`, 'temp/server-darwin-x64.zip'),
downloadTo(`${config.newLanguageServerUrl}/${config.newLanguageServerVersion}/win32-x86.zip`, 'temp/server-win32-x86.zip'),
]);
}

Expand All @@ -41,6 +45,11 @@ async function build() {

// ls
await fc('temp/EmmyLua-LS-all.jar', 'server/EmmyLua-LS-all.jar', { mkdirp: true });
// new ls
await decompress('temp/server-linux-x64.zip', 'server/');
await decompress('temp/server-darwin-x64.zip', 'server/');
await decompress('temp/server-darwin-arm64.zip', 'server/');
await decompress('temp/server-win32-x86.zip', 'server/');
}

build().catch(console.error);
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "emmylua",
"displayName": "EmmyLua",
"description": "EmmyLua for vscode",
"version": "0.5.19",
"version": "0.6.0",
"icon": "res/icon.png",
"publisher": "tangzx",
"engines": {
"vscode": "^1.82.0"
"vscode": "^1.87.0"
},
"categories": [
"Programming Languages",
Expand Down Expand Up @@ -284,6 +284,11 @@
"default": [],
"description": "%emmylua.source.roots%"
},
"emmylua.new.languageServer": {
"type": "boolean",
"default": false,
"description": "%emmylua.new.languageServer%"
},
"emmylua.completion.caseSensitive": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -465,7 +470,7 @@
"devDependencies": {
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.21",
"@types/vscode": "1.79.0",
"@types/vscode": "1.87.0",
"download": "^7.1.0",
"eslint": "^8.11.0",
"filecopy": "^4.0.2",
Expand All @@ -476,6 +481,6 @@
"@vscode/debugprotocol": "^1.61.0",
"iconv-lite": "^0.6.3",
"smart-buffer": "^4.0.1",
"vscode-languageclient": "8.0.2"
"vscode-languageclient": "9.0.1"
}
}
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"emmylua.hint.overrideHint": "method override hint",
"emmylua.constructor.names" : "constructor function names",
"emmylua.requirelike.names": "set function names like require",
"emmylua.new.languageServer" : "Use new language server",

"emmylua.typecheck.anyTypeCanAssignToAnyDefineType": "A custom defined type can accept assignments of type any",
"emmylua.typecheck.defineAnyTypeCanBeAssignedByAnyVariable": "A custom defined type can accept any parameter",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"emmylua.hint.overrideHint": "方法覆盖夫类方法的override hint",
"emmylua.constructor.names" : "构造函数名称列表",
"emmylua.requirelike.names": "设置类似require的函数名列表",

"emmylua.new.languageServer" : "使用emmylua新的语言服务",

"emmylua.typecheck.anyTypeCanAssignToAnyDefineType": "定义类型能接受any 类型的赋值",
"emmylua.typecheck.defineAnyTypeCanBeAssignedByAnyVariable": "定义类型为any可以接受任何参数",
"emmylua.typecheck.defineTypeCanReceiveNilType": "任何参数类型能接受nil",
Expand Down
4 changes: 2 additions & 2 deletions src/emmyCtx.ts → src/emmyContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import { LanguageClient } from 'vscode-languageclient/node';
import { IProgressReport, ServerStatusParams } from './lspExt';

export class EmmyCtx {
export class EmmyContext {
public LANGUAGE_ID: string = "lua"; //EmmyLua
public client?: LanguageClient;
private readonly statusBar: vscode.StatusBarItem;
Expand All @@ -11,7 +11,7 @@ export class EmmyCtx {
constructor(
public debugMode: boolean,
public extensionContext: vscode.ExtensionContext,

public newLanguageServer: boolean
) {
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
this.loadBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
Expand Down
86 changes: 65 additions & 21 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,41 @@ import { EmmyConfigWatcher, IEmmyConfigUpdate } from './emmyConfigWatcher';
import { EmmyNewDebuggerProvider } from './debugger/new_debugger/EmmyNewDebuggerProvider';
import { EmmyAttachDebuggerProvider } from './debugger/attach/EmmyAttachDebuggerProvider';
import { EmmyLaunchDebuggerProvider } from './debugger/launch/EmmyLaunchDebuggerProvider';
import { EmmyCtx } from './emmyCtx';
import { active } from './tree_view/treeView';
import { InlineDebugAdapterFactory} from './debugger/DebugFactory'
import { EmmyContext } from './emmyContext';
import { InlineDebugAdapterFactory } from './debugger/DebugFactory'
import * as os from 'os';
import * as fs from 'fs';

export let ctx: EmmyCtx;
export let ctx: EmmyContext;
let activeEditor: vscode.TextEditor;
let javaExecutablePath: string | null;
let configWatcher: EmmyConfigWatcher;

export function activate(context: vscode.ExtensionContext) {
console.log("emmy lua actived!");
ctx = new EmmyCtx(
ctx = new EmmyContext(
process.env['EMMY_DEV'] === "true",
context
context,
vscode.workspace.getConfiguration("emmylua").get("new.languageServer") as boolean
);
javaExecutablePath = findJava();
if (!ctx.newLanguageServer) {
javaExecutablePath = findJava();
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration, null, context.subscriptions));
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(onDidChangeTextDocument, null, context.subscriptions));
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(onDidChangeActiveTextEditor, null, context.subscriptions));
context.subscriptions.push(vscode.commands.registerCommand("emmy.restartServer", restartServer));
context.subscriptions.push(vscode.commands.registerCommand("emmy.showReferences", showReferences));
context.subscriptions.push(vscode.commands.registerCommand("emmy.insertEmmyDebugCode", insertEmmyDebugCode));
context.subscriptions.push(vscode.commands.registerCommand("emmy.stopServer", stopServer));
}

context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration, null, context.subscriptions));
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(onDidChangeTextDocument, null, context.subscriptions));
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(onDidChangeActiveTextEditor, null, context.subscriptions));
context.subscriptions.push(vscode.commands.registerCommand("emmy.restartServer", restartServer));
context.subscriptions.push(vscode.commands.registerCommand("emmy.showReferences", showReferences));
context.subscriptions.push(vscode.commands.registerCommand("emmy.insertEmmyDebugCode", insertEmmyDebugCode));
context.subscriptions.push(vscode.commands.registerCommand("emmy.stopServer", stopServer));
context.subscriptions.push(vscode.languages.setLanguageConfiguration("lua", new LuaLanguageConfiguration()));

configWatcher = new EmmyConfigWatcher();
configWatcher.onConfigUpdate(onConfigUpdate);
context.subscriptions.push(configWatcher);
startServer();
registerDebuggers();
registerTreeView();
return {
reportAPIDoc: (classDoc: any) => {
ctx?.client?.sendRequest("emmy/reportAPI", classDoc);
Expand Down Expand Up @@ -105,10 +108,6 @@ function registerDebuggers() {
}));
}

function registerTreeView() {
active(ctx)
}

function onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) {
if (activeEditor && activeEditor.document === event.document
&& activeEditor.document.languageId === ctx.LANGUAGE_ID
Expand Down Expand Up @@ -171,7 +170,7 @@ async function validateJava(): Promise<void> {

async function startServer() {
try {
if (!ctx.debugMode) {
if (!ctx.debugMode && !ctx.newLanguageServer) {
await validateJava();
}
} catch (error) {
Expand Down Expand Up @@ -230,13 +229,58 @@ async function doStartServer() {
});
return Promise.resolve(result);
};
} else {
} else if (!ctx.newLanguageServer) {
const cp = path.resolve(context.extensionPath, "server", "*");
const exePath = javaExecutablePath || "java";
serverOptions = {
command: exePath,
args: ["-cp", cp, "com.tang.vscode.MainKt", "-XX:+UseG1GC", "-XX:+UseStringDeduplication"]
};
} else {
let platform: string = os.platform();

let command: string = "";
switch (platform) {
case "win32":
command = path.join(
context.extensionPath,
'server',
'win32-x64',
'LanguageServer.exe'
)
break;
case "linux":
command = path.join(
context.extensionPath,
'server',
'linux-x64',
'LanguageServer'
)
fs.chmodSync(command, '777');
break;
case "darwin":
if (os.arch() === "arm64") {
command = path.join(
context.extensionPath,
'server',
'darwin-arm64',
'LanguageServer'
);
} else {
command = path.join(
context.extensionPath,
'server',
'darwin-x64',
'LanguageServer'
);
}
fs.chmodSync(command, '777');
break;
}
serverOptions = {
command: command,
args: []
};
}

ctx.client = new LanguageClient(ctx.LANGUAGE_ID, "EmmyLua plugin for vscode.", serverOptions, clientOptions);
Expand Down
Loading

0 comments on commit 56e4271

Please sign in to comment.