devicetree-language-server 0.6.7 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,232 @@
1
- ![Build Status](https://github.com/kylebonnici/dts-lsp/actions/workflows/node.js.yml/badge.svg)
1
+ ![Build Status](https://github.com/kylebonnici/dts-lsp/actions/workflows/build-test.yml/badge.svg)
2
2
 
3
3
  # DTS Language Server
4
4
 
5
5
  This LSP is intended to be used with DTS Devicetree Specification Release v0.4 (https://devicetree.org)
6
6
 
7
+ ## Table of Contents
8
+
9
+ - [Features](#features)
10
+ - [Go to Definition](#go-to-definition)
11
+ - [Go to Declarations](#go-to-declarations)
12
+ - [Go to References](#go-to-references---find-all-references)
13
+ - [Hover](#hover)
14
+ - [Formatting](#formatting)
15
+ - [Semantic Tokens](#semantic-tokens)
16
+ - [Document Symbols](#document-symbols)
17
+ - [Workspace Symbols](#workspace-symbols)
18
+ - [Diagnostics](#diagnostics)
19
+ - [Completions](#completions)
20
+ - [Refactoring](#refactoring)
21
+ - [Code Actions](#code-actions)
22
+ - [Installation](#installation)
23
+ - [Usage](#usage)
24
+ - [Zephyr](#zephyr-configuration-example)
25
+ - [Linux](#linux)
26
+ - [Devicetree-Org](#with-devicetree-org-bindings)
27
+ - [Sample Editor configurations](#sample-editor-configurations)
28
+ - [kakoune](#kakoune)
29
+ - [Neovim - lazygit](#neovim---lazygit)
30
+ - [Helix](#helix)
31
+ - [coc.nvim](#coco-nvim)
32
+ - [Vim 9 - yegappan lsp](#vim-9---yegappan-lsp)
33
+
34
+ ## Features
35
+
36
+ ### Go to Definition
37
+
38
+ On node name/label reference; will list all the places where the node is altered. /delete-node/ cases are not listed.
39
+ On property name; will list all the places where the property is assigned a value. Note: defining a property name with no assign (empty) is equal to assigning a truthful value and hence it will also be shown.
40
+
41
+ ![Go to Definition](/docs/GoToDefinition.gif)
42
+
43
+ NOTE: If for example a node with name node1 has been created, then deleted, and then created again, depending on where the definition call is made in the file, in one case one will get the definition from before the delete keyword, and in the other case the definition from under the delete keyword.
44
+
45
+ #### Zephyr - DT_MACROS
46
+
47
+ You can also use `Go to Definition` on a selected number of DT\_ APIs found in zephyr and get Hovers to help explain Node state or even DT_MACRO result for the current active Devicetree context
48
+
49
+ ![DT Macro Go to Definition](/docs/DT_Definition.gif)
50
+
51
+ ### Go to Declarations
52
+
53
+ On node name/label reference; will list the first places where the node is created.
54
+ On property name; will list the first places where the property is assigned a value for the first time. Note: defining a property name with no assign (empty) is equal to assigning a truthful value and hence it will also be shown.
55
+
56
+ ![Go to Declarations](/docs/GoToDeclarations.gif)
57
+
58
+ NOTE: The declarations will stop at the definition, hence, if for example a node with name node1 has been created, then deleted, and then created again, depending on where the declarations call is made in the file, in one case one will get the declarations from before the delete keyword up to the delete keyword, and in the other case from the delete keyword (excluded) onwards.
59
+
60
+ #### Zephyr - DT_MACROS
61
+
62
+ You can also use `Go to Declarations` on a selected number of DT\_ APIs found in zephyr and get Hovers to help explain Node state or even DT_MACRO result for the current active Devicetree context
63
+
64
+ ![DT Macro Go to Declarations](/docs/DT_Decleration.gif)
65
+
66
+ ### Go to References - Find All References
67
+
68
+ - On node name/label reference; will list all the places where the node is used by name, label or in some path.
69
+ - On property name; will list all the places where the property referred to including /delete-property/.
70
+
71
+ ![Go to References](/docs/GoToReferences.gif)
72
+
73
+ NOTE: The references will stop at the definition, hence, if for example a node with name node1 has been created, then deleted, and then created again, depending on where the reference call is made in the file, in one case one will get the ones from before the delete keyword up to the delete keyword, and in the other case from the delete keyword (excluded) onwards.
74
+
75
+ ### Hover
76
+
77
+ On hover over the node name, a tooltip will show the final state of that node. If bindings are used it will also include the description from the binding files.
78
+
79
+ ![On Hover](/docs/OnHoverNode.gif)
80
+
81
+ When hovering over a deleted state you can see the state of the item just before the delete action.
82
+
83
+ ![On Hover Deleted State](/docs/OnHoverDeleteState.gif)
84
+
85
+ #### Zephyr - DT_MACROS
86
+
87
+ You can also hover on a selected number of DT\_ APIs found in zephyr and get Hovers to help explain Node state or even DT_MACRO result for the current active Devicetree context
88
+
89
+ ![DT Hover](/docs/DT_Hover.gif)
90
+
91
+ ### Formatting
92
+
93
+ This LSP follows the [Zephyr Style Guide](https://docs.zephyrproject.org/latest/contribute/style/devicetree.html) and is used in CI to validate all files upstream.
94
+
95
+ ![Formatting](/docs/Formatting.gif)
96
+
97
+ ### Semantic Tokens
98
+
99
+ Every element in the document will have semantic tokens to help highlight and color code the items.
100
+
101
+ ![Document Symbols](/docs/SemanticTokens.png)
102
+
103
+ ### Document Symbols
104
+
105
+ Every element in the document will have document symbols to help navigate the document in a tree format.
106
+
107
+ ![Semantic Tokens](/docs/DocumentSymbols.gif)
108
+
109
+ ### Workspace Symbols
110
+
111
+ You can also navigate the active context using workspace symbols.
112
+
113
+ ![Workspace Symbols](/docs/WorkspaceSymbols.png)
114
+
115
+ ### Diagnostics
116
+
117
+ #### Reports generic syntax issues such as missing "," , "}" , ">" etc...
118
+
119
+ ![Generic Syntax.png](/docs/GenericSyntax.png)
120
+
121
+ #### Reports when property has been replaced by a later definition and provides document link to where it has been redefined
122
+
123
+ ![Property Replaced](/docs/PropertyReplaced.png)
124
+
125
+ #### Reports when node has been deleted and provides document link to where the delete was done
126
+
127
+ ![Node Delete](/docs/NodeDelete.png)
128
+
129
+ #### Reports when property has been deleted and provides document link to where it has been redefined
130
+
131
+ ![Property Deleted](/docs/PropertyDeleted.png)
132
+
133
+ #### Reports label conflicts
134
+
135
+ ![Label Conflict](/docs/LabelConflict.png)
136
+
137
+ #### Duplicate node name in the same node
138
+
139
+ ![Duplicate Node Name](/docs/DuplicateNodeName.png)
140
+
141
+ #### Reports when deleting a node/property that does not exist
142
+
143
+ ![Invalid Delete](/docs/InvalidDelete.png)
144
+
145
+ #### Reports CPreprocessor issues such as missing macro, invalid argument count etc.
146
+
147
+ ![Macro Issues](/docs/MacroIssues.png)
148
+
149
+ #### Compares the node address and ensures that it matches the reg property, and that the reg values use the appropriate number of values as defined `#address-cells`
150
+
151
+ ![Node Address Mismatch](/docs/NodeAddressMismatch.png)
152
+
153
+ #### Reports property type mismatch errors
154
+
155
+ ![Wrong Property Type](/docs/PropertyType.png)
156
+
157
+ #### Reports prop-encoded-values errors when these need to follow some expected pattern e.g interrupts/nexus
158
+
159
+ ![Missing Flag Value](/docs/PHandelArray.png)
160
+
161
+ #### Bus type validation when using Zephyr bindings
162
+
163
+ ![Bus Type Validation](/docs/BusType.png)
164
+
165
+ ### Completions
166
+
167
+ Completions are context aware of the document state on the line the action is requested.
168
+
169
+ #### Node path completion
170
+
171
+ ![Node Path Completion](/docs/NodePathCompletion.gif)
172
+
173
+ #### Label reference completion reference node creation and property assignment
174
+
175
+ ![Label Reference Completion](/docs/LabelRefCompletion.gif)
176
+
177
+ #### Delete Node:
178
+
179
+ Suggests appropriate type e.g. by reference or node name.
180
+ Does not suggest keyword if no delete is possible.
181
+
182
+ ![Delete Node Completion](/docs/DeleteNodeCompletion.gif)
183
+
184
+ #### Delete Property:
185
+
186
+ Suggests property names available in that context.
187
+ Does not suggest keyword if no delete is possible.
188
+
189
+ ![Delete Property Completion](/docs/DeletePropertyCompletion.gif)
190
+
191
+ #### Default values for standard types
192
+
193
+ ![Enum Completion](/docs/EnumCompletion.gif)
194
+
195
+ #### Zephyr DT_MACRO Completion
196
+
197
+ ![DT MACRO Completion](/docs/DT_Completaion.gif)
198
+
199
+ ### Refactoring
200
+
201
+ Refactoring is possible on the following elements:
202
+
203
+ - Node names
204
+ - Node labels
205
+ - Property names
206
+
207
+ ![Rename Node](/docs/RenameNode.gif)
208
+
209
+ Given that in some cases the files included in a devicetree might come from an SDK which should not be edited, one can configure "lockRenameEdits" in the settings to lock refactoring from being permitted on any elements which would otherwise effect edits to the files listed in "lockRenameEdits".
210
+
211
+ ### Code Actions
212
+
213
+ - Adds missing syntax e.g. ';', '<', '>', ',' etc...
214
+ - Removes syntactically incorrect spaces:
215
+ - Between node name, '@' and address
216
+ - In node path reference
217
+ - Removes ';' when used without any statement
218
+ - Supports SourceFixAll/QuickFixes
219
+
220
+ ### Something else in mind?
221
+
222
+ Contributions are welcome or reach out on GitHub with requests.
223
+
7
224
  ## Installation
8
225
 
9
226
  The language server can be found on https://www.npmjs.com/package/devicetree-language-server.
10
227
 
11
228
  To install run
12
- `npm i devicetree-language-server`
229
+ `npm i -g devicetree-language-server`
13
230
 
14
231
  The LSP has only been tested with Node 20.
15
232
 
@@ -17,6 +234,8 @@ The LSP has only been tested with Node 20.
17
234
 
18
235
  This extension needs a client that supports Configuration Capability. The format for the configuration setting is of the type `Settings` as shown below:
19
236
 
237
+ At the moment, this LSP only supports bindings for the Zephyr project and has experimental support for Devicetree-Org Bindings.
238
+
20
239
  ```typescript
21
240
  interface Context {
22
241
  ctxName?: string | number;
@@ -29,7 +248,7 @@ interface Context {
29
248
  deviceOrgTreeBindings?: string[];
30
249
  deviceOrgBindingsMetaSchema?: string[];
31
250
  lockRenameEdits?: string[];
32
- showFormattingErrorAsDiagnostics?: boolean;
251
+ formattingErrorAsDiagnostics?: boolean;
33
252
  compileCommands?: string;
34
253
  }
35
254
 
@@ -49,7 +268,79 @@ interface Settings {
49
268
  }
50
269
  ```
51
270
 
52
- ### Sample configurations
271
+ ### Zephyr configuration example
272
+
273
+ ```json
274
+ {
275
+ "devicetree.cwd": "/User/workspace/zephyr",
276
+ "devicetree.defaultIncludePaths": [
277
+ "./zephyr/dts",
278
+ "./zephyr/dts/arm",
279
+ "./zephyr/dts/arm64/",
280
+ "./zephyr/dts/riscv",
281
+ "./zephyr/dts/common",
282
+ "./zephyr/dts/vendor",
283
+ "./zephyr/include",
284
+ "./zephyr/dts/xtensa"
285
+ ],
286
+ "devicetree.defaultBindingType": "Zephyr",
287
+ "devicetree.defaultZephyrBindings": ["./zephyr/dts/bindings"],
288
+ "devicetree.contexts": [
289
+ {
290
+ "devicetree.cwd": "/opt/nordic/ncs/v3.0.0",
291
+ "bindingType": "Zephyr",
292
+ "zephyrBindings": ["./zephyr/dts/bindings", "./nrf/dts/bindings"],
293
+ "includePaths": [
294
+ "./zephyr/dts",
295
+ "./zephyr/dts/arm",
296
+ "./zephyr/dts/arm64/",
297
+ "./zephyr/dts/riscv",
298
+ "./zephyr/dts/common",
299
+ "./zephyr/dts/vendor",
300
+ "./zephyr/include",
301
+ "./zephyr/dts/xtensa"
302
+ ],
303
+ "dtsFile": "./zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts",
304
+ "overlays": ["/User/project/myOverlay.overlay"]
305
+ }
306
+ ]
307
+ }
308
+ ```
309
+
310
+ ### Linux
311
+
312
+ ```json
313
+ {
314
+ "devicetree.cwd": "/Users/user/Workspace/linux/",
315
+ "devicetree.defaultIncludePaths": ["include"],
316
+ "devicetree.defaultBindingType": "DevicetreeOrg",
317
+ "devicetree.defaultDeviceOrgBindingsMetaSchema": [],
318
+ "devicetree.defaultDeviceOrgTreeBindings": []
319
+ }
320
+ ```
321
+
322
+ #### With Devicetree-Org Bindings
323
+
324
+ ```json
325
+ {
326
+ "devicetree.cwd": "/Users/user/Workspace/linux/",
327
+ "devicetree.defaultIncludePaths": ["include"],
328
+ "devicetree.defaultBindingType": "DevicetreeOrg",
329
+ "devicetree.defaultDeviceOrgBindingsMetaSchema": [
330
+ "/Users/user/Workspace/linuxBindings/dt-schema/dtschema/meta-schemas" // https://github.com/devicetree-org/dt-schema/tree/main/dtschema/meta-schemas
331
+ ],
332
+ "devicetree.defaultDeviceOrgTreeBindings": [
333
+ "/Users/user/Workspace/linuxBindings/dt-schema/dtschema/schemas", // https://github.com/devicetree-org/dt-schema/tree/main/dtschema/schemas
334
+ "/Users/user/Workspace/linux/Documentation/devicetree/bindings" // https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings
335
+ ]
336
+ }
337
+ ```
338
+
339
+ #### Note
340
+
341
+ Devicetree-Org bindings are experimental.
342
+
343
+ ### Sample Editor configurations
53
344
 
54
345
  #### kakoune
55
346
 
@@ -81,7 +372,7 @@ EOF
81
372
  }
82
373
  ```
83
374
 
84
- #### neovim
375
+ #### Neovim - lazygit
85
376
 
86
377
  Example setup using [lazygit](https://github.com/jesseduffield/lazygit)
87
378
 
@@ -169,138 +460,210 @@ return {
169
460
  }
170
461
  ```
171
462
 
172
- ## Using Devicetree-Org bindings example settings
173
-
174
- ```json
175
- {
176
- "devicetree": {
177
- "cwd": "/Users/user/Workspace/linux/",
178
- "defaultIncludePaths": ["include"],
179
- "defaultBindingType": "DevicetreeOrg",
180
- "defaultDeviceOrgBindingsMetaSchema": [
181
- "/Users/user/Workspace/linuxBindings/dt-schema/dtschema/meta-schemas" // https://github.com/devicetree-org/dt-schema/tree/main/dtschema/meta-schemas
182
- ],
183
- "defaultDeviceOrgTreeBindings": [
184
- "/Users/user/Workspace/linuxBindings/dt-schema/dtschema/schemas", // https://github.com/devicetree-org/dt-schema/tree/main/dtschema/schemas
185
- "/Users/user/Workspace/linux/Documentation/devicetree/bindings" // https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings
186
- ]
187
- }
188
- }
189
- ```
190
-
191
- ## Functionality
192
-
193
- Follows Devicetree Specification Release v0.4
194
-
195
- ### Semantic Tokens
196
-
197
- Every element in the document will have semantic tokens to help highlight and color code the items.
198
-
199
- ### Document Symbols
200
-
201
- Every element in the document will have document symbols to help navigate the document in a tree format.
202
-
203
- ### Diagnostics
204
-
205
- #### Syntax
206
-
207
- - Reports when property has been redefined and provides document link to where it has been redefined
208
- - Reports when node has been deleted and provides document link to where it has been redefined
209
- - Reports when property has been deleted and provides document link to where it has been redefined
210
- - Reports label reuse conflicts
211
- - Warns about duplicate node name in the same node
212
- - Reports when deleting a node/property that does not exist
213
- - Reports generic syntax issues such as missing "," , "}" , "<" , ">" etc...
214
- - Reports missing values for properties
215
- - Reports basic CPreprocessor issues such as missing macro name
216
-
217
- #### Types
463
+ #### Helix
218
464
 
219
- - Supports standard types as defined in chapter 2 of Devicetree Specification Release v0.4
220
- - Reports property type mismatch errors
221
- - Reports prop-encoded-values errors when these need to follow some pattern e.g interrupts
222
- - Compares the node address and ensures that it matches the reg property, and that the reg values use the appropriate number of values as defined by other properties
223
- - And more... (See Chapter 2 of Devicetree Specification Release v0.4 https://devicetree.org)
465
+ Contribution by [bextract](https://github.com/bextract)
224
466
 
225
- ### Document Formatting
226
-
227
- - Fixes indentation
228
- - Fixes spacing between label names on assign
229
- - Fixes spacing between node name and '{'
230
- - Ensures new line between node/property/keywords. If there is one additional line this is kept; any additional lines are cleaned up.
231
- - Ensures that composite values have single space between ',' and next value
232
- - Ensures that Bytestring/prop-encoded-array values have single space between each value
233
- - Ensures that no space exists between ';' and end of statement
234
-
235
- ### Completions
236
-
237
- Completions are context aware of the document state on the line the action is requested.
238
-
239
- - Node path completion
240
- - Label reference completion in property assign values
241
- - Delete Node:
242
- - Suggests appropriate type e.g. by reference or node name
243
- - Does not suggest keyword if no delete is possible
244
- - Delete Property:
245
- - Suggests property names available in that context
246
- - Does not suggest keyword if no delete is possible
247
- - Default values for standard types (e.g state)
248
-
249
- ### Code Actions
250
-
251
- - Adds missing syntax e.g. ';', '<', '>', ',' etc...
252
- - Removes syntactically incorrect spaces:
253
- - Between node name, '@' and address
254
- - In node path reference
255
- - Removes ';' when used without any statement
256
- - Suggests solutions for incomplete /delete-node/ keywords
257
- - Suggests solutions for incomplete /delete-property/ keywords
258
- - Supports SourceFixAll/QuickFixes
259
-
260
- ### Find Definition
261
-
262
- - On node name/label reference; will list all the places where the node is altered. /delete-node/ cases are not listed.
263
- - On property name; will list all the places where the property is assigned a value. Note: defining a property name with no assign (empty) is equal to assigning a truthful value and hence it will also be shown.
264
-
265
- NOTE: If for example a node with name node1 has been created, then deleted, and then created again, depending on where the definition call is made in the file, in one case one will get the definition from before the delete keyword, and in the other case the definition from under the delete keyword.
266
-
267
- ### Find Declarations
268
-
269
- - On node name/label reference; will list the first places where the node is created.
270
- - On property name; will list the first places where the property is assigned a value for the first time. Note: defining a property name with no assign (empty) is equal to assigning a truthful value and hence it will also be shown.
271
-
272
- NOTE: The declarations will stop at the definition, hence, if for example a node with name node1 has been created, then deleted, and then created again, depending on where the declarations call is made in the file, in one case one will get the declarations from before the delete keyword up to the delete keyword, and in the other case from the delete keyword (excluded) onwards.
273
-
274
- ### Find References
275
-
276
- - On node name/label reference; will list all the places where the node is used by name, label or in some path.
277
- - On property name; will list all the places where the property referred to including /delete-property/.
278
-
279
- NOTE: The references will stop at the definition, hence, if for example a node with name node1 has been created, then deleted, and then created again, depending on where the reference call is made in the file, in one case one will get the ones from before the delete keyword up to the delete keyword, and in the other case from the delete keyword (excluded) onwards.
280
-
281
- ### Hover
282
-
283
- - On hover over the node name, a tooltip will show the final state of that node. If bindings are used it will also include the description from the binding files.
284
-
285
- ## Bindings
286
-
287
- At the moment, this LSP only supports bindings for the Zephyr project. Feel free to contribute to this project or reach out to request other formats.
288
-
289
- ## Refactoring
467
+ ```
468
+ [[language]]
469
+ name = "devicetree"
470
+ language-servers = ["devicetree_ls"]
471
+
472
+ [language-server.devicetree_ls]
473
+ command = "devicetree-language-server"
474
+ args = ["--stdio"]
475
+ config = { devicetree = { cwd = "/home/bex/zephyrproject/", defaultIncludePaths = ["./zephyr/dts","./zephyr/dts/arm","./zephyr/dts/arm64","./zephyr/dts/riscv","./zephyr/dts/common","./zephyr/dts/vendor","./zephyr/include","./zephyr/dts/xtensa"], defaultBindingType = "Zephyr", defaultZephyrBindings = ["./zephyr/dts/bindings"], contexts = [] } }
476
+ ```
290
477
 
291
- Refactoring is possible on the following elements:
478
+ #### coco nvim
292
479
 
293
- - Node names
294
- - Node labels
295
- - Property names
480
+ ```
481
+ {
482
+ "suggest.completionItemKindLabels": {
483
+ "keyword": "",
484
+ "variable": "",
485
+ "value": "",
486
+ "operator": "Ψ",
487
+ "constructor": "",
488
+ "function": "ƒ",
489
+ "reference": "渚",
490
+ "constant": "",
491
+ "method": "",
492
+ "struct": "פּ",
493
+ "class": "",
494
+ "interface": "",
495
+ "text": "",
496
+ "enum": "",
497
+ "enumMember": "",
498
+ "module": "",
499
+ "color": "",
500
+ "property": "",
501
+ "field": "料",
502
+ "unit": "",
503
+ "event": "鬒",
504
+ "file": "",
505
+ "folder": "",
506
+ "snippet": "",
507
+ "typeParameter": "",
508
+ "default": ""
509
+ },
510
+ "diagnostic.errorSign": "❗",
511
+ "diagnostic.warningSign": "💡",
512
+ "diagnostic.infoSign": "💡",
513
+ "diagnostic.hintSign": "💡",
514
+ "diagnostic.signPriority": 100,
515
+ "languageserver": {
516
+ "devicetree_ls": {
517
+ "command": "devicetree-language-server",
518
+ "args": ["--stdio"],
519
+ "filetypes": ["dts", "dtsi"],
520
+ "rootPatterns": [".git"],
521
+ "initializationOptions": {
522
+ "AutomaticWorkspaceInit": true
523
+ },
524
+ "settings": {
525
+ "devicetree": {
526
+ "cwd": "/home/user/Workspace/Kernel/linux",
527
+ "defaultIncludePaths": ["./include"],
528
+ "defaultBindingType": "DevicetreeOrg",
529
+ "contexts": []
530
+ }
531
+ }
532
+ }
533
+ }
534
+ }
535
+ ```
296
536
 
297
- Given that in some cases the files included in a devicetree might come from an SDK which should not be edited, one can configure "lockRenameEdits" in the settings to lock refactoring from being permitted on any elements which would otherwise effect edits to the files listed in "lockRenameEdits".
537
+ #### Vim 9 - yegappan lsp
298
538
 
299
- ### Road Map
539
+ Contribution by [jclsn](https://github.com/jclsn)
300
540
 
301
- - Formatting
302
- - Clean up trailing white spaces
303
- - Implement syntax for Ternary operator
304
- - Implement "Device Node Requirements" (chapter 3 - Devicetree Specification Release v0.4)
305
- - Write more unit tests
306
- - Let me know what you should be added or changed
541
+ ```
542
+ set encoding=utf-8
543
+ set nocompatible
544
+ colorscheme habamax
545
+
546
+ call plug#begin('$MYVIMDIR/plugged')
547
+ Plug 'yegappan/lsp'
548
+ call plug#end()
549
+
550
+ let lspOpts = #{
551
+ \ aleSupport: v:false,
552
+ \ autoComplete: v:true,
553
+ \ autoHighlight: v:false,
554
+ \ autoHighlightDiags: v:true,
555
+ \ autoPopulateDiags: v:false,
556
+ \ completionMatcher: 'case',
557
+ \ completionMatcherValue: 1,
558
+ \ diagSignErrorText: '❗',
559
+ \ diagSignHintText: '💡',
560
+ \ diagSignInfoText: '💡',
561
+ \ diagSignWarningText: '💡',
562
+ \ diagSignPriority: {
563
+ \ 'Error': 100,
564
+ \ 'Warning': 99,
565
+ \ 'Information': 98,
566
+ \ 'Hint': 97
567
+ \ },
568
+ \ echoSignature: v:false,
569
+ \ hideDisabledCodeActions: v:false,
570
+ \ highlightDiagInline: v:true,
571
+ \ hoverInPreview: v:false,
572
+ \ ignoreMissingServer: v:false,
573
+ \ keepFocusInDiags: v:true,
574
+ \ keepFocusInReferences: v:true,
575
+ \ completionTextEdit: v:true,
576
+ \ diagVirtualTextAlign: 'above',
577
+ \ diagVirtualTextWrap: 'default',
578
+ \ noNewlineInCompletion: v:false,
579
+ \ omniComplete: v:null,
580
+ \ omniCompleteAllowBare: v:false,
581
+ \ outlineOnRight: v:false,
582
+ \ outlineWinSize: 20,
583
+ \ popupBorder: v:true,
584
+ \ popupBorderHighlight: 'Title',
585
+ \ popupBorderHighlightPeek: 'Special',
586
+ \ popupBorderSignatureHelp: v:false,
587
+ \ popupHighlightSignatureHelp: 'Pmenu',
588
+ \ popupHighlight: 'Normal',
589
+ \ semanticHighlight: v:true,
590
+ \ showDiagInBalloon: v:true,
591
+ \ showDiagInPopup: v:true,
592
+ \ showDiagOnStatusLine: v:false,
593
+ \ showDiagWithSign: v:true,
594
+ \ showDiagWithVirtualText: v:false,
595
+ \ showInlayHints: v:false,
596
+ \ showSignature: v:true,
597
+ \ snippetSupport: v:false,
598
+ \ ultisnipsSupport: v:false,
599
+ \ useBufferCompletion: v:false,
600
+ \ usePopupInCodeAction: v:false,
601
+ \ useQuickfixForLocations: v:false,
602
+ \ vsnipSupport: v:false,
603
+ \ bufferCompletionTimeout: 100,
604
+ \ customCompletionKinds: v:false,
605
+ \ completionKinds: {},
606
+ \ filterCompletionDuplicates: v:false,
607
+ \ condensedCompletionMenu: v:false,
608
+ \ }
609
+ autocmd User LspSetup call LspOptionsSet(lspOpts)
610
+
611
+ let lspServers = [#{
612
+ \ name: 'devicetree_ls',
613
+ \ filetype: ['dts', 'dtsi'],
614
+ \ path: 'devicetree-language-server',
615
+ \ args: ['--stdio'],
616
+ \
617
+ \ root_uri: {server_info -> lsp#utils#path_to_uri(
618
+ \ lsp#utils#find_nearest_parent_file_directory(expand('%:p'), '.git', '.')
619
+ \ )
620
+ \ },
621
+ \
622
+ \ initializationOptions: #{
623
+ \ settings: #{
624
+ \ devicetree: #{
625
+ \ cwd: getcwd(),
626
+ \ defaultIncludePaths: [
627
+ \ './include',
628
+ \ ],
629
+ \ defaultBindingType: 'DevicetreeOrg',
630
+ \ contexts: []
631
+ \ }
632
+ \ }
633
+ \ }
634
+ \ }]
635
+
636
+ autocmd User LspSetup call LspAddServer(lspServers)
637
+
638
+ " Remap leader key to space
639
+ nnoremap <SPACE> <Nop>
640
+ let mapleader = " "
641
+ let maplocalleader = "-"
642
+
643
+ nnoremap <leader>ac :LspCodeAction<CR>
644
+ nnoremap <silent> <leader>pe :LspDiagPrev<CR>
645
+ nnoremap <silent> <leader>ne :LspDiagNext<CR>
646
+ nnoremap <silent> <leader>pd :LspPeekDefinition<CR>
647
+ nnoremap <silent> <leader>pdc :LspPeekDeclaration<CR>
648
+ nnoremap <silent> <leader>pr :LspPeekReferences<CR>
649
+ nnoremap <silent> <leader>ol :LspOutline<CR>
650
+ nnoremap <silent> <leader>rn :LspRename<CR>
651
+ nnoremap <leader>cl :LspCodeLens<CR>
652
+
653
+ function! s:SmartHover() abort
654
+ let result = execute('LspHover')
655
+ if result =~ 'Error'
656
+ call feedkeys('K', 'n')
657
+ endif
658
+ endfunction
659
+
660
+ nnoremap <silent> K :call <SID>SmartHover()<CR>
661
+
662
+ nnoremap <silent> gd :LspGotoDefinition<CR>
663
+ nnoremap <silent> gy :LspGotoTypeDef<CR>
664
+ nnoremap <silent> gi :LspGotoImpl<CR>
665
+ nnoremap <silent> gdc :LspGotoDeclaration<CR>
666
+
667
+ command! -nargs=0 -bar -range=% Format <line1>,<line2>LspFormat
668
+ set formatexpr=lsp#lsp#FormatExpr() " Map LspFormat to the gq command
669
+ ```