devicetree-language-server 0.6.7 → 0.6.8

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