Skip to content

Commit

Permalink
Add Neovim plugin instead of example configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jayadamsmorgan committed Apr 14, 2024
1 parent a532d87 commit 54044f5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
40 changes: 1 addition & 39 deletions Editors/Neovim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,7 @@ This language server also works great along side with Apple's [pkl-neovim][uri-p

## Installation

1. Install [PklLanguageServer][uri-pkl-ls]

1. Add a hook to let Neovim recognize Pkl filetype:

**Note:** If you have [pkl-neovim][uri-pkl-neovim] installed you can skip this step.

```lua
vim.cmd([[autocmd BufRead,BufNewFile PklProject,*.pkl,*.pcf setfiletype pkl]])
```

3. Install [nvim-lspconfig][uri-lspconfig] and add custom server to configs:

```lua
local configs = require("lspconfig.configs")

configs.pklls = {
default_config = {
cmd = {
"pkl-lsp-server", -- OR path to where you installed `pkl-lsp-server`
-- You can also spawn it with some options:
-- "-l", "debug", "-f", "pkl-lsp.log",
},
filetypes = { "pkl" },
root_dir = require("lspconfig/util").root_pattern(".git", "PklProject", ".pkl"),
settings = {},
},
}
```

4. Now you can configure the server itself as any other LSP:

```lua
local lspconfig = require("lspconfig")

lspconfig["pklls"].setup({
on_attach = on_attach, -- Change to your `on_attach`
capabilities = capabilities, -- Change to your `capabilities`
})
```
WIP

[uri-pkl-ls]: https://github.com/jayadamsmorgan/PklLanguageServer
[uri-pkl-neovim]: https://github.com/apple/pkl-neovim
Expand Down
1 change: 1 addition & 0 deletions Editors/Neovim/pklls-nvim/ftdetect/pkl.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
au BufRead,BufNewFile PklProject,*.pkl,*.pcf set filetype=pkl
29 changes: 29 additions & 0 deletions Editors/Neovim/pklls-nvim/lua/pklls-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local M = {}

function M.setup(config)
local lspConfigExists, configs = pcall(require, "lspconfig.configs")
if not lspConfigExists then
print("[pklls-nvim] 'lspconfig' not found")
print("[pklls-nvim] Please install 'neovim/nvim-lspconfig'")
return
end
configs.pklls = {
default_config = {
cmd = {
"pkl-lsp-server",
},
filetypes = { "pkl" },
root_dir = require("lspconfig/util").root_pattern(".git", "PklProject", ".pkl"),
settings = {},
},
}
local lspConfigExists, lspconfig = pcall(require, "lspconfig")
if not lspConfigExists then
print("[pklls-nvim] 'lspconfig' not found")
print("[pklls-nvim] Please install 'neovim/nvim-lspconfig'")
return
end
lspconfig.pklls.setup(config)
end

return M
5 changes: 5 additions & 0 deletions Editors/Neovim/pklls-nvim/plugin/pklls-nvim.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if vim.g.pklls_plugin_version then
return
end

vim.g.pklls_plugin_version = '0.0.3'

0 comments on commit 54044f5

Please sign in to comment.