English | 中文
(This repo is a fork of https://github.com/thqby/vscode-autohotkey2-lsp)
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 or alipay qrcode or paypal
- AutoHotkey v2 Language Support
Rename variables and function names in the scope in batches.
Simple syntax error diagnosis.
Supports intelligent completion of variables, functions, parameters, class names, and method names within the scope (by simple type deduction), and supports the completion of include files and function libraries.
Support for intelligent prompts for function parameters.
- Displays class, method, function, variable, label, hotkey, hot string, block information in the left outline column.
- press Ctrl + P, Input @symbol_name to retrieve and jump
- You can comment a method with a semicolon or /* */ on the top line of a function, variable. Jsdoc-style annotations can mark variable types.
/**
* @param {Array} a - a param
* @return {Integer}
*/
fn(a*) {
/** @type {Map} */
d := Map()
/**
* @var {Map} e
* @var {Object} f
*/
e := Map(), f := {}
/** @type {(a,b)=>Integer} */
cb := (a, b) => a + b
/** @type {ComObject<Excel.Sheet.12,Workbook>} */
wb := ComObject('Excel.Sheet.12')
return a[1] + a[2]
}
class abc {
/** @type {Map} */
p := dosomethingandreturnmap()
}
Semantic highlighting is an addition to syntax highlighting, resolves symbols in the context of a project. The editor applies the highlighting from semantic tokens on top of the highlighting from grammars.
usage: Add ;;
(default) or ; TODO
to the comment code Tags.
Compute and resolve colors inside a document to provide color picker in editor.
Supports hover prompts and comments for scoped variables, functions, global classes, and labels.
usage: Move the mouse over the symbol.
- Support for jumping to the declaration location of scoped variables, functions, global classes, and labels.
- usage: Press ctrl Then move the mouse over to the code and click.
See all the source code locations where a certain variable/function is being used.
usage:
- Right-click the popup menu and click "Format document".
- Press
Shift+Alt+F
. - Supports formatting code blocks when typing '}', formatting lines and indenting lines when typing '\n'. (
editor.formatOnType
needs to be enabled) - Supports the use of formatting instructions
;@format array_style: collapse, object_style: expand
to change the object style of different blocks
Fold the part between ;@region tag
and ;@endregion
, ;{
and ;}
;#region tag
code
;#endregion
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.
; array.d.ahk
; #ClsName represents the ahk built-in class
/** @extends {#Array} */
class Array<T = Any> {
/** jsdoc-default */
Filter(FilterFunc) => Array<T>
}
; array.zh-cn.d.ahk
; #ClsName 表示ahk内置类
/** @extends {#Array} */
class Array<T = Any> {
/** jsdoc-zh */
Filter(FilterFunc) => Array<T>
}
; array.ahk
; %A_Locale% is VSCode's Display Language
;@reference array.%A_Locale%.d.ahk
Array.Prototype.DefineProp('Filter', { call: Array_Filter_impl })
Open the help file and navigate to the keyword at the current cursor.
Run the currently open script.
Run the code snippet at the cursor selection.
Compile the script to generate executable EXE files.
No additional configuration is required to start the installed Debug extensions, and support debugging with parameters.
Generate JSDOC-style comments for a function or method.
- Install Node.js.
- Download vscode-autohotkey2-lsp server using command line, or download and unpack through vscode marketplace.
mkdir vscode-autohotkey2-lsp
cd vscode-autohotkey2-lsp
curl.exe -L -o install.js https://raw.githubusercontent.com/thqby/vscode-autohotkey2-lsp/main/tools/install.js
node install.js
- Set the LSP configuration of the editor that support LSP(Language Server Protocol), such as Sublime Text4, Vim, Neovim, Emacs, etc.
Package Control: Install Package
, and install Sublime LSP plug-in.Preferences: LSP Settings
, add lsp configuration, language selector, and syntax highlighting. This is a simple example syntax highlighting, save the file in a similar pathC:\Users\<USERNAME>\AppData\Roaming\Sublime Text\Packages\User\LSP-ahk2\AutoHotkey2.sublime-syntax
.
{
"clients": {
"lsp-ahk2": {
"enabled": true,
"command": [
"node",
"<VSCODE-AUTOHOTKEY2-LSP>/server/dist/server.js",
"--stdio"
], // Update the path of node.exe(maybe it's already in PATH, so you don't need to set it) and the folder of vscode-autohotkey2-lsp
"selector": "source.ahk2", // Same as scope in AutoHotkey2.sublime-syntax
"schemes": ["file", "buffer", "res"],
"initializationOptions": {
"locale": "en-us", // or "zh-cn"
"AutoLibInclude": "Disabled", // or "Local" or "User and Standard" or "All"
"CommentTags": "^;;\\s*(?<tag>.+)",
"CompleteFunctionParens": false,
"Diagnostics": {
"ClassStaticMemberCheck": true,
"ParamsCheck": true
},
"ActionWhenV1IsDetected": "Continue",
"FormatOptions": {
"array_style": "none", // or "collapse" or "expand"
"break_chained_methods": false,
"ignore_comment": false,
"indent_string": "\t",
"max_preserve_newlines": 2,
"brace_style": "One True Brace", // or "Allman" or "One True Brace Variant"
"object_style": "none", // or "collapse" or "expand"
"preserve_newlines": true,
"space_after_double_colon": true,
"space_before_conditional": true,
"space_in_empty_paren": false,
"space_in_other": true,
"space_in_paren": false,
"wrap_line_length": 0
},
"InterpreterPath": "C:/Program Files/AutoHotkey/v2/AutoHotkey.exe",
"WorkingDirs": [],
"SymbolFoldingFromOpenBrace": false
}
}
},
"semantic_highlighting": true
}
- Download coc.nvim plugin.
cd $VIMRUNTIME\plugin
git clone --branch release https://github.com/neoclide/coc.nvim.git --depth=1
- Open (n)vim and enter the command
:CocConfig
to enter thecoc.nvim
configuration file to add configuration information.
{
"languageserver": {
"lsp-ahk2": {
"module": "<VSCODE-AUTOHOTKEY2-LSP>/server/dist/server.js",
"filetypes": ["autohotkey"],
"args": ["--node-ipc"],
"initializationOptions": {
// Same as initializationOptions for Sublime Text4
}
}
}
}
- Download nvim-lspconfig.
- Add the following to your NVIM configuration (init.lua e.g.). Ensure that
cmd
points to the path of your vscode-autohotkey2-lsp installation andInterpreterPath
points to your AHK exe.
local function custom_attach(client, bufnr)
require("lsp_signature").on_attach({
bind = true,
use_lspsaga = false,
floating_window = true,
fix_pos = true,
hint_enable = true,
hi_parameter = "Search",
handler_opts = { "double" },
})
end
local ahk2_configs = {
autostart = true,
cmd = {
"node",
vim.fn.expand("$HOME/vscode-autohotkey2-lsp/server/dist/server.js"),
"--stdio"
},
filetypes = { "ahk", "autohotkey", "ah2" },
init_options = {
locale = "en-us",
InterpreterPath = "C:/Program Files/AutoHotkey/v2/AutoHotkey.exe",
-- Same as initializationOptions for Sublime Text4, convert json literal to lua dictionary literal
},
single_file_support = true,
flags = { debounce_text_changes = 500 },
capabilities = capabilities,
on_attach = custom_attach,
}
local configs = require "lspconfig.configs"
configs["ahk2"] = { default_config = ahk2_configs }
local nvim_lsp = require("lspconfig")
nvim_lsp.ahk2.setup({})
- Add the following lines to your emacs config file
(add-to-list 'eglot-server-programs '(ahk-mode "node" "<VSCODE-AUTOHOTKEY2-LSP>/server/dist/server.js" "--stdio"))
visit https://github.dev or https://vscode.dev in Chrome/Edge
, and install thqby.vscode-autohotkey2-lsp