Skip to content

Repository files navigation

AWK Language Server

testsnpm

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:

callale#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:

ifexecutable('awk-language-server')
auUserlsp_setupcalllsp#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<<EOFlocalconfigs=require('lspconfig.configs')
locallspconfig=require('lspconfig')
ifnotconfigs.awklspthenconfigs.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
}
},
}
endlspconfig.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.

About

Port awk-ide-vscode to vim.

Topics

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages