Skip to content

Commit

Permalink
Merge thqby 2.5.4 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-wiemer authored Nov 2, 2024
2 parents 22d94d8 + a6c9fc5 commit 53d6b48
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

github: thqby
custom:
- https://qr.alipay.com/fkx19566u7ctegoppmu5i13
- https://github.com/thqby/vscode-autohotkey2-lsp/raw/main/pic/alipay.jpg
- https://www.paypal.me/thqby
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
!server/dist/*.js
!server/dist/*.ahk
!syntaxes/**
!ahk2.configuration.json
!language-configuration.json
!icon.png
!icon_filetype.png
!package.json
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.5.4

- 修复[#610](https://github.com/thqby/vscode-autohotkey2-lsp/issues/610)
- 修复[#615](https://github.com/thqby/vscode-autohotkey2-lsp/issues/615)
- 修复[#623](https://github.com/thqby/vscode-autohotkey2-lsp/issues/623)
- 修复[#628](https://github.com/thqby/vscode-autohotkey2-lsp/issues/628)

## 2.5.3

- 修复[#603](https://github.com/thqby/vscode-autohotkey2-lsp/issues/603)
Expand Down
4 changes: 3 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
AutoHotkey v2 语言支持 for VS Code, 功能实现基于 v2 语法分析。
支持在`Chrome/Edge`等浏览器中使用 https://vscode.devhttps://github.dev/github/dev

如果你想捐款,捐款可以寄到这里: [支付宝转账](https://qr.alipay.com/fkx19566u7ctegoppmu5i13)[支付宝二维码](./pic/alipay.jpg)[paypal](https://paypal.me/thqby)

- [AutoHotkey v2 语言支持](#autohotkey-v2-语言支持)
- [语言特性](#语言特性)
- [重命名符号](#重命名符号)
Expand Down Expand Up @@ -159,7 +161,7 @@ code

### 声明文件

声明文件是以 .d.ahk 为文件名后缀的文件, 用来描述已实现的函数或类等, 不包含代码的实现部分, 默认被同名的ahk文件引用, 语法参考扩展提供的 `ahk2.d.ahk`. 声明文件可以扩展或改写ahk内置函数或类的声明, 也可以将注释文档从源码中分离来提供多语言版本的智能感知等.
声明文件是以 .d.ahk 为文件名后缀的文件, 用来描述已实现的函数或类等, 不包含代码的实现部分, 默认被同名的ahk文件引用, 语法参考扩展提供的 `ahk2.d.ahk`. 声明文件可以扩展或改写ahk内置函数或类的声明, 也可以将注释文档从源码中分离来提供多语言版本的智能感知等. 另外, 可以修改扩展的`AutoHotkey2.Syntaxes`设置项将内置声明文件替换为第三方的声明文件, 如[GroggyOtter's ahkv2_definition_rewrite](https://github.com/GroggyOtter/ahkv2_definition_rewrite).

```
; array.d.ahk
Expand Down
52 changes: 27 additions & 25 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ async function runScript(textEditor: TextEditor, runSelection = false) {
.then(r => r ? setInterpreter() : undefined);
return;
}
let selectedText = '', path = '*', command = `"${executePath}" /ErrorStdOut=utf-8 `;
let selecttext = '', path = '*', command = `"${executePath}" /ErrorStdOut=utf-8 `;
let startTime: Date;
const showOutput = getConfigIDE<ShowOutput>(CfgKey.ShowOutput, 'always');
if (showOutput === 'always')
Expand All @@ -368,56 +368,58 @@ async function runScript(textEditor: TextEditor, runSelection = false) {

// Build the command
if (runSelection)
selectedText = textEditor.selections.map(textEditor.document.getText).join('\n');
selecttext = textEditor.selections.map(textEditor.document.getText).join('\n');
else if (textEditor.document.isUntitled || !textEditor.document.uri.toString().startsWith('file:///'))
selectedText = textEditor.document.getText();
selecttext = textEditor.document.getText();
executePath.replace(/^(.+[\\/])AutoHotkeyUX\.exe$/i, (...m) => {
const lc = m[1] + 'launcher.ahk';
if (existsSync(lc))
command = `"${executePath}" "${lc}" `;
return '';
})

// Spawn the process
let process: ChildProcess & { path?: string };
if (selectedText !== '') {
});
const opt = {
env: Object.fromEntries(Object.entries(process.env)
.filter(it => !/^(CHROME|ELECTRON_RUN|FPS_BROWSER|VSCODE)_/.test(it[0]))),
shell: true
};
let cp: ChildProcess & { path?: string };
if (selecttext !== '') {
if (ahkStatusBarItem.text.endsWith('[UIAccess]')) {
path = resolve(__dirname, 'temp.ahk');
writeFileSync(path, selectedText);
writeFileSync(path, selecttext);
command += `"${path}"`, startTime = new Date();
process = spawn(command, { cwd: `${resolve(textEditor.document.fileName, '..')}`, shell: true });
cp = spawn(command, { cwd: `${resolve(textEditor.document.fileName, '..')}`, ...opt });
unlinkSync(path);
} else {
command += path, startTime = new Date();
process = spawn(command, { cwd: `${resolve(textEditor.document.fileName, '..')}`, shell: true });
process.stdin?.write(selectedText), process.stdin?.end();
cp = spawn(command, { cwd: `${resolve(textEditor.document.fileName, '..')}`, ...opt });
cp.stdin?.write(selecttext), cp.stdin?.end();
}
} else {
if (textEditor.document.isUntitled)
return;
await commands.executeCommand('workbench.action.files.save');
path = textEditor.document.fileName, command += `"${path}"`, startTime = new Date();
process = spawn(command, { cwd: resolve(path, '..'), shell: true });
cp = spawn(command, { cwd: resolve(path, '..'), ...opt });
}

if (process.pid) {
outputchannel.appendLine(`[Running] [pid:${process.pid}] ${command}`);
ahkprocesses.set(process.pid, process);
process.path = path;
if (cp.pid) {
outputchannel.appendLine(`[Running] [pid:${cp.pid}] ${command}`);
ahkprocesses.set(cp.pid, cp);
cp.path = path;
commands.executeCommand('setContext', ahkIsRunningContext, true);
process.stderr?.on('data', (data) => {
cp.stderr?.on('data', (data) => {
outputchannel.appendLine(decode(data));
});
process.on('error', (error) => {
cp.on('error', (error) => {
outputchannel.appendLine(JSON.stringify(error));
ahkprocesses.delete(process.pid!);
ahkprocesses.delete(cp.pid!);
});
process.stdout?.on('data', (data) => {
cp.stdout?.on('data', (data) => {
outputchannel.appendLine(decode(data));
});
process.on('exit', (code) => {
outputchannel.appendLine(`[Done] [pid:${process.pid}] exited with code=${code} in ${((new Date()).getTime() - startTime.getTime()) / 1000} seconds`);
ahkprocesses.delete(process.pid!);
cp.on('exit', (code) => {
outputchannel.appendLine(`[Done] [pid:${cp.pid}] exited with code=${code} in ${((new Date()).getTime() - startTime.getTime()) / 1000} seconds`);
ahkprocesses.delete(cp.pid!);
if (!ahkprocesses.size)
commands.executeCommand('setContext', ahkIsRunningContext, false);
});
Expand Down
3 changes: 3 additions & 0 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ switch (process.argv[2]) {
async function build_cli() {
server_opt.bundle = true;
server_opt.minify = true;
server_opt.entryPoints = ['server/cli/*.ts'];
server_opt.outbase = 'server/cli';
server_opt.outdir = 'server/cli';
server_opt.sourcemap = false;
const start = new Date();
await build(server_opt);
console.log(`build finished in ${new Date() - start} ms`);
Expand Down
6 changes: 6 additions & 0 deletions ahk2.configuration.json → language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
["'", "'"],
["%", "%"]
],
"folding": {
"markers": {
"start": "^\\s*;\\s*@region\\b",
"end": "^\\s*;\\s*@endregion\\b"
}
},
"indentationRules": {
"increaseIndentPattern": "^((?!;).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$",
"decreaseIndentPattern": "^((?!.*?/\\*).*\\*/)?\\s*[\\])}].*$",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-autohotkey2-lsp",
"displayName": "AutoHotkey v2 Language Support",
"version": "2.5.3",
"version": "2.5.4",
"description": "AutoHotkey v2 Language Support, based on vscode-lsp.",
"categories": [
"Formatters",
Expand Down Expand Up @@ -801,7 +801,7 @@
".ah2",
".ahk2"
],
"configuration": "./ahk2.configuration.json",
"configuration": "./language-configuration.json",
"icon": {
"dark": "icon_filetype.png",
"light": "icon_filetype.png"
Expand Down
Binary file added pic/alipay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
AutoHotkey v2 Language support for VS Code, features realization based on v2 syntax analysis.
Supports running on the Web, such as `Chrome/Edge`. https://vscode.dev or https://github.dev/github/dev

If you wish to donate, donations can be sent here: [alipay](https://qr.alipay.com/fkx19566u7ctegoppmu5i13) or [alipay qrcode](./pic/alipay.jpg) or [paypal](https://paypal.me/thqby)

- [AutoHotkey v2 Language Support](#autohotkey-v2-language-support)
- [Language Features](#language-features)
- [Rename Symbol](#rename-symbol)
Expand Down Expand Up @@ -41,6 +43,7 @@ Supports running on the Web, such as `Chrome/Edge`. https://vscode.dev or https:
- [Vim and Neovim](#vim-and-neovim)
- [Emacs](#Emacs)
- [Use in Web Browser](#use-in-web-browser)
- [Sponsor](#sponsor)

## Language Features

Expand Down Expand Up @@ -162,7 +165,7 @@ code

### Declaration document

The declaration file is a file with the suffix of `.d.ahk` as the file name, which is used to describe the implemented functions or classes, etc., does not contain the implementation part of the code, and is referenced by the ahk file with the same name by default, and the syntax refers to `ahk2.d.ahk` provided by the extension. The declaration file can extend or rewrite the declaration of ahk built-in functions or classes, and the annotation document can be separated from the source code to provide a multilingual version of intellisense.
The declaration file is a file with the suffix of `.d.ahk` as the file name, which is used to describe the implemented functions or classes, etc., does not contain the implementation part of the code, and is referenced by the ahk file with the same name by default, and the syntax refers to `ahk2.d.ahk` provided by the extension. The declaration file can extend or rewrite the declaration of ahk built-in functions or classes, and the annotation document can be separated from the source code to provide a multilingual version of intellisense. In addition, you can modify `AutoHotkey2.Syntaxes` setting of extension to replace the built-in declaration file with a third-party declaration file, such as [GroggyOtter's ahkv2_defintion_rewrite](https://github.com/GroggyOtter/ahkv2_definition_rewrite).

```
; array.d.ahk
Expand Down
7 changes: 3 additions & 4 deletions server/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ function main() {
const options: Record<string, string> = {};
process.argv.slice(2).forEach((s) => {
const arr = s.split('=');
options[arr[0]] = arr[1];
options[arr[0]] = arr[1].replace(/^(['"])(.*)\1$/, '$2');
});
let path: string = options.path ?? '';
path = path.replace(/^(['"])(.*)\1$/, '$2');
const path: string = options.path ?? '';
if (!path) return;
try {
const td = openFile(path, false);
if (!td) return;
const sc = new Lexer(td).beautify({});
const sc = new Lexer(td).beautify(options);
console.log(sc);
} catch (e) {
console.error(e);
Expand Down
13 changes: 8 additions & 5 deletions server/src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ export class Lexer {
const last_case = case_pos.pop();
if (case_pos.push(tk.offset), last_case)
_this.addFoldingRange(last_case, lk.offset, 'case');
tk.hover_word = 'default';
nexttoken(), next = false;
tk.topofline ||= -1;
break;
Expand Down Expand Up @@ -4162,7 +4163,7 @@ export class Lexer {
else {
if (!m.match(/\.\w+$/))
m = m + '.dll';
m = find_include_path(m, [], dlldir, true)?.path ?? m;
m = find_include_path(m, [], dlldir || _this.scriptpath, true)?.path ?? m;
if (m.includes(':'))
_this.dllpaths.push(m.replace(/\\/g, '/'));
else _this.dllpaths.push((dlldir && existsSync(dlldir + m) ? dlldir + m : m).replace(/\\/g, '/'));
Expand Down Expand Up @@ -6128,7 +6129,7 @@ export class Lexer {
}
let t: AhkSymbol | undefined, parent: AhkSymbol | undefined, is_global: boolean | 1 = true;
if (name.startsWith('$'))
return (node = from_d(this.d ? uri : this.d_uri)) && { node, uri, is_global: true };
return (node = from_d(this.d ? uri : this.d_uri) ?? this.typedef[name]) && { node, uri, is_global: true };
if ((scope = position && this.searchScopedNode(position) as FuncNode)) {
if (scope.kind === SymbolKind.Class)
scope = undefined;
Expand Down Expand Up @@ -6281,7 +6282,7 @@ export class Lexer {
case SemanticTokenTypes.parameter: kind = SymbolKind.Variable; break;
}
} else kind = SymbolKind.Variable;
} else if (token.type === 'TK_LABEL')
} else if (token.type === 'TK_LABEL' && !token.hover_word)
kind = SymbolKind.Field;
} else if (pt?.content.startsWith('#'))
token = pt, text = pt.content;
Expand Down Expand Up @@ -6942,7 +6943,9 @@ export function decltype_expr(lex: Lexer, tk: Token, end_pos: number | Position,
syms = new Set;
const node = r.node;
if (node.kind === SymbolKind.Variable) {
for (const n of decltype_var(node, lex, pos, r.scope, _this))
if (r.uri !== lex.uri)
pos.line = NaN;
for (const n of decltype_var(node, lexers[r.uri] ?? lex, pos, r.scope, _this))
syms.add(n);
} else if (syms.add(node), r.is_this !== undefined) {
that = _this ?? node as ClassNode;
Expand Down Expand Up @@ -7505,7 +7508,7 @@ export function decltype_returns(sym: AhkSymbol, lex: Lexer, _this?: ClassNode):
}

let tps: AhkSymbol[];
if (sym.returns) {
if (sym.returns && sym.uri === lex.uri) {
sym.cached_types = [ANY], tps = [];
for (let i = 0, r = sym.returns, l = r.length; i < l; i += 2)
tps.push(...decltype_expr(lex, lex.find_token(r[i], true), r[i + 1], _this));
Expand Down
7 changes: 6 additions & 1 deletion syntaxes/ahk2.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@
"prefix": "static"
},
{
"body": "throw ${1|Error,MemoryError,OSError,TargetError,TimeoutError,TypeError,UnsetError,MemberError,PropertyError,MethodError,UnsetItemError,ValueError,IndexError,ZeroDivisionError|}('${2:Message}', ${3:A_ThisFunc}, ${4:ExtraInfo})",
"body": "switch",
"description": "Compares a value with multiple cases and executes the statements of the first match.",
"syntax": "switch [SwitchValue, CaseSense] {\n\tcase Value, Expression: \n\n\tdefault: \n\n}"
},
{
"body": "throw",
"description": "Indicates that an error has occurred. The signal can be caught by a try-catch statement.",
"prefix": "throw"
},
Expand Down
3 changes: 1 addition & 2 deletions syntaxes/zh-cn/ahk2.d.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,8 @@ Cos(Number) => Float

/**
* 防止当前线程被其他线程中断, 或使其能够被中断.
* @param OnOffNumeric
*/
Critical(OnOffNumeric := 'On') => Integer
Critical(OnOffNumeric: Integer | 'On' | 'Off' := 'On') => Integer

/**
* 从日期-时间值中添加或减去时间.
Expand Down
5 changes: 5 additions & 0 deletions syntaxes/zh-cn/ahk2.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@
"description": "静态变量始终是隐式局部变量,但与局部变量有所不同,因为它们的值在两次调用之间被记住.",
"syntax": "static [Var]\nstatic Method()\nstatic Property"
},
{
"body": "switch",
"description": "将一个值与多个case进行比较, 并执行第一个匹配的语句.",
"syntax": "switch [SwitchValue, CaseSense] {\n\tcase Value, Expression: \n\n\tdefault: \n\n}"
},
{
"body": "throw",
"description": "表示发生错误.可以通过try-catch语句捕获该信号.",
Expand Down
2 changes: 1 addition & 1 deletion tools/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ function get_latest_ahk2lsp() {
if (name.includes('/client/') || name.includes('/browser'))
return false;
if (
name.endsWith('/ahk2.configuration.json') ||
name.endsWith('/language-configuration.json') ||
name.endsWith('.png') ||
name.endsWith('.tmlanguage.json')
)
Expand Down

0 comments on commit 53d6b48

Please sign in to comment.