Skip to content

Beaglefoot/awk-language-server

Repository files navigation

AWK Language Server

tests npm

Implementation of AWK Language Server based on tree-sitter and tree-sitter-awk.

Features

  • Syntax highlighting
  • Diagnostics
  • Autocomplete
    • Builtins
    • User defined symbols
  • Hints on hover
    • Builtins
    • User defined symbols
  • Go to definition
  • Code outline & symbol references
  • Document symbols
  • Workspace symbols
  • Rename symbols
  • Code formatting (requires prettier-plugin-awk)

How to use with editors

VSCode

VSCode extension is developed as part of this project and can be downloaded from marketplace here.

Emacs

Add to your config:

(with-eval-after-load 'eglot
  (add-to-list 'eglot-server-programs
               '(awk-mode . ("awk-language-server"))))

Support is built-in, so no action is needed besides turning lsp-mode on.

Vim

  • npm install -g "awk-language-server@>=0.5.2"
  • Choose and install plugin with support for LSP (some examples are below).
  • Configure plugin to use awk-language-server.

Add following to .vimrc:

call ale#linter#Define('awk', {
\   'name': 'awk-language-server',
\   'lsp': 'stdio',
\   'executable': 'awk-language-server',
\   'command': '%e',
\   'project_root': { _ -> expand('%p:h') }
\})

Note that with such configuration project_root will be set to directory containing opened awk file.

Edit config with :CocConfig command and add the following:

{
  "languageserver": {
    "awk": {
      "command": "awk-language-server",
      "args": [],
      "filetypes": ["awk"]
    }
  }
}

It works partially unless support for multi-root workspaces is implemented by vim-lsp.

Add to your .vimrc:

if executable('awk-language-server')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'awk-language-server',
        \ 'cmd': {server_info->['awk-language-server']},
        \ 'allowlist': ['awk'],
        \ })
endif

Nvim

A default config for awk-language-server was merged into nvim-lspconfig. It works only if workspaceFolders requests are handled and a default handler for these was only just set to be added upstream in Neovim 0.7, so the config itself is gated for use only in Neovim >= v0.7. For users below that version, please use a manual config that handles these requests by adding the following to your init.vim (or init.lua):

lua << EOF
local configs = require('lspconfig.configs')
local lspconfig = require('lspconfig')
if not configs.awklsp then
  configs.awklsp = {
    default_config = {
      cmd = { 'awk-language-server' },
      filetypes = { 'awk' },
      single_file_support = true,
      handlers = {
        ['workspace/workspaceFolders'] = function()
          return {{
            uri = 'file:https://' .. vim.fn.getcwd(),
            name = 'current_dir',
          }}
        end
      }
    },
  }
end
lspconfig.awklsp.setup{}
EOF

Notes

AWK Language Server supports AWKPATH. If you prefer to place all your awk libs in some directory and then @include it without dir name, then simply pass this env variable to your editor of choice.

AWKPATH=./include vim main.vim

or

export AWKPATH=./include
vim main.vim

Check this cool project for inspiration.

Contributing

Thanks for considering it.

Please check this guide.