Beaglefoot / awk-language-server

Language Server for AWK and associated VSCode client extension
https://marketplace.visualstudio.com/items?itemName=beaglefoot.awk-ide-vscode
MIT License
90 stars 5 forks source link
awk gawk language-server language-server-protocol lsp

AWK Language Server

tests npm

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

Features

How to use with editors

VSCode

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

Emacs

Eglot

Add to your config:

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

lsp-mode

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

Vim

ALE

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.

CoC

Edit config with :CocConfig command and add the following:

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

vim-lsp

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

nvim-lspconfig

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://' .. 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.