thqby / vscode-autohotkey2-lsp

Autohotkey v2 Language Support using vscode-lsp.
https://marketplace.visualstudio.com/items?itemName=thqby.vscode-autohotkey2-lsp
GNU Lesser General Public License v3.0
207 stars 21 forks source link
ahk autohotkey language-server lsp v2 vscode vscode-extension

English | 中文

AutoHotkey v2 Language Support

installs version

Repositories: Github | Gitee

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

Language Features

Rename Symbol

Rename variables and function names in the scope in batches.

rename

Diagnostics

Simple syntax error diagnosis.

diagnostics

IntelliSense

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.

snippet1

snippet2

Signature

Support for intelligent prompts for function parameters.

signature

Document Symbol

  1. Displays class, method, function, variable, label, hotkey, hot string, block information in the left outline column.
  2. press Ctrl + P, Input @symbol_name to retrieve and jump
  3. 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 Highlight

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.

semanticTokens

Tags

usage: Add ;;(default) or ; TODO to the comment code Tags.

codeSymbole

Document Color

Compute and resolve colors inside a document to provide color picker in editor.

documentcolor

Hover

Supports hover prompts and comments for scoped variables, functions, global classes, and labels.
usage: Move the mouse over the symbol.

hover

Goto Definition

  1. Support for jumping to the declaration location of scoped variables, functions, global classes, and labels.
  2. usage: Press ctrl Then move the mouse over to the code and click.

gotoDefinition

Find All References

See all the source code locations where a certain variable/function is being used.

CodeFormat

usage:

codeFormat

Custom folding

Fold the part between ;@region tag and ;@endregion, ;{ and ;}

;#region tag
code
;#endregion

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.

; 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 })

Context Menu

Quick Help

Open the help file and navigate to the keyword at the current cursor.

Run Script

Run the currently open script.

Run Selected Script

Run the code snippet at the cursor selection.

Compile Script

Compile the script to generate executable EXE files.

Debug Script

No additional configuration is required to start the installed Debug extensions, and support debugging with parameters.

Generate Comment

Generate JSDOC-style comments for a function or method.

Use in other editors

  1. Install Node.js.
  2. 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
  1. Set the LSP configuration of the editor that support LSP(Language Server Protocol), such as Sublime Text4, Vim, Neovim, Emacs, etc.

Sublime Text4

{
  "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
}

Vim and Neovim

COC

cd $VIMRUNTIME\plugin
git clone --branch release https://github.com/neoclide/coc.nvim.git --depth=1
{
  "languageserver": {
    "lsp-ahk2": {
      "module": "<VSCODE-AUTOHOTKEY2-LSP>/server/dist/server.js",
      "filetypes": ["autohotkey"],
      "args": ["--node-ipc"],
      "initializationOptions": {
        // Same as initializationOptions for Sublime Text4
      }
    }
  }
}

nvim-lspconfig

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({})

Emacs

Eglot

(add-to-list 'eglot-server-programs '(ahk-mode "node" "<VSCODE-AUTOHOTKEY2-LSP>/server/dist/server.js" "--stdio"))

Use in Web Browser

visit https://github.dev or https://vscode.dev in Chrome/Edge, and install thqby.vscode-autohotkey2-lsp