Skip to content

Commit 55d718c

Browse files
committed
added setup() function to platformio module to have userconfiguration such as lsp
1 parent 73d16cc commit 55d718c

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ return {
5353

5454
#### Usage `:h PlatformIO`
5555

56+
### Configuration
57+
```lua
58+
require('platformio').setup({
59+
lsp = "ccls" --default: ccls, other option: clangd
60+
-- If you pick clangd, it also creates compile_commands.json
61+
})
62+
```
63+
5664
### Lazy loading
5765

5866
It's possible to lazy load the plugin using Lazy.nvim, this will load the plugins only when it is needed, to enable lazy loading, add this plugin spec to your config.

lua/platformio/init.lua

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local M = {}
2+
3+
local default_config = {
4+
lsp = 'ccls',
5+
}
6+
7+
M.config = vim.deepcopy(default_config)
8+
9+
function M.setup(user_config)
10+
local valid_keys = {
11+
lsp = true,
12+
}
13+
for key, _ in pairs(user_config or {}) do
14+
if not valid_keys[key] then
15+
local error_message = string.format(
16+
"Invalid configuration key: '%s'\n%s",
17+
key,
18+
debug.traceback("Stack trace:")
19+
)
20+
vim.api.nvim_err_writeln(error_message)
21+
return
22+
end
23+
end
24+
M.config = vim.tbl_deep_extend('force', default_config, user_config or {})
25+
end
26+
27+
return M

lua/platformio/pioinit.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ local M = {}
22

33
local pickers = require 'telescope.pickers'
44
local finders = require 'telescope.finders'
5-
local conf = require('telescope.config').values
5+
local telescope_conf = require('telescope.config').values
66
local actions = require 'telescope.actions'
77
local action_state = require 'telescope.actions.state'
88
local entry_display = require 'telescope.pickers.entry_display'
99
local make_entry = require 'telescope.make_entry'
1010
local utils = require 'platformio.utils'
1111
local previewers = require 'telescope.previewers'
12+
local config = require('platformio').config
1213

1314
local boardentry_maker = function(opts)
1415
local displayer = entry_display.create {
@@ -61,12 +62,13 @@ local function pick_framework(board_details)
6162
.. ' --project-option "framework='
6263
.. selected_framework
6364
.. '"'
65+
.. (config.lsp == "clangd" and " && pio run -t compiledb " or "")
6466
.. utils.extra
6567
utils.ToggleTerminal(command, 'float')
6668
end)
6769
return true
6870
end,
69-
sorter = conf.generic_sorter(opts),
71+
sorter = telescope_conf.generic_sorter(opts),
7072
})
7173
:find()
7274
end
@@ -103,7 +105,7 @@ local function pick_board(json_data)
103105
end, 0)
104106
end,
105107
},
106-
sorter = conf.generic_sorter(opts),
108+
sorter = telescope_conf.generic_sorter(opts),
107109
})
108110
:find()
109111
end

plugin/platformio.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-- *: Any number of arguments (including none).
66
-- +: At least one argument.
77
-- -1: Zero or one argument (like ?, explicitly).
8-
8+
local platformio = require('platformio')
99

1010
-- Pioinit
1111
vim.api.nvim_create_user_command('Pioinit', function()

0 commit comments

Comments
 (0)