devicetree-language-server 0.0.6 → 0.0.7

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.
Files changed (3) hide show
  1. package/README.md +193 -0
  2. package/dist/server.js +92 -92
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,193 @@
1
+ ![Build Status](https://github.com/kylebonnici/dts-lsp/actions/workflows/node.js.yml/badge.svg)
2
+
3
+ # DTS Language Server
4
+
5
+ This LSP is intended to be used with DTS Devicetree Specification Release v0.4 (https://devicetree.org)
6
+
7
+ ## Installation
8
+
9
+ The language server can be found on https://www.npmjs.com/package/devicetree-language-server.
10
+
11
+ To install run
12
+ `npm i devicetree-language-server`
13
+
14
+ The LSP has only been tested with Node 20.
15
+
16
+ ## Usage
17
+
18
+ This extension needs a client that supports Configuration Capability. The format for the configuration setting is of the type `Settings` as shown below:
19
+
20
+ ```typescript
21
+ interface Context {
22
+ ctxName: string | number;
23
+ cwd?: string;
24
+ includePaths?: string[];
25
+ dtsFile: string;
26
+ overlays?: string[];
27
+ bindingType?: BindingType;
28
+ zephyrBindings?: string[];
29
+ }
30
+
31
+ interface Settings {
32
+ cwd?: string;
33
+ defaultBindingType?: BindingType;
34
+ defaultZephyrBindings?: string[];
35
+ defaultIncludePaths?: string[];
36
+ contexts?: Context[];
37
+ preferredContext?: string | number;
38
+ lockRenameEdits?: string[];
39
+ autoChangeContext?: boolean;
40
+ allowAdhocContexts?: boolean;
41
+ }
42
+ ```
43
+
44
+ Sample configuration in for `kakoune` with `Zephyr` 3.7.99 or lator.
45
+ Contribution by [topisani](https://github.com/topisani)
46
+
47
+ ```
48
+ hook -group lsp-project-zephyr global BufSetOption filetype=(devicetree) %{
49
+ eval %sh{
50
+ root=$(eval "$kak_opt_lsp_find_root" .build_info.yml $(: kak_buffile))
51
+ [ -e "$root/.build_info.yml" ] || exit 0
52
+
53
+ settings=$(cat ".build_info.yml" | yq -c '{ "defaultIncludePaths": .cmake.devicetree."include-dirs", "contexts": [{ "bindingType": "Zephyr", "zephyrBindings": .cmake.devicetree."bindings-dirs", "includePaths": .cmake.devicetree."include-dirs", "dtsFile": .cmake.devicetree.files[0], "overlays": .cmake.devicetree.files[1:] }], "preferredContext": 0 } | { devicetree: {settings: {"_": {devicetree: .}}}}' | yj -jt | sed '/^\[devicetree\]$/d')
54
+
55
+ cat <<EOF
56
+ set-option buffer lsp_servers %{
57
+ [devicetree]
58
+ root = '$root'
59
+ command = "npm"
60
+ args = ["x", "--", "devicetree-language-server", "--stdio"]
61
+ # command = "node"
62
+ # args = ["/home/topisani/git/dts-lsp/server/dist/server.js", "--stdio"]
63
+ settings_section = "_"
64
+
65
+ $settings
66
+ }
67
+ EOF
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## Functionality
73
+
74
+ Follows Devicetree Specification Release v0.4
75
+
76
+ ### Semantic Tokens
77
+
78
+ Every element in the document will have semantic tokens to help highlight and color code the items.
79
+
80
+ ### Document Symbols
81
+
82
+ Every element in the document will have document symbols to help navigate the document in a tree format.
83
+
84
+ ### Diagnostics
85
+
86
+ #### Syntax
87
+
88
+ - Reports when property has been redefined and provides document link to where it has been redefined
89
+ - Reports when node has been deleted and provides document link to where it has been redefined
90
+ - Reports when property has been deleted and provides document link to where it has been redefined
91
+ - Reports label reuse conflicts
92
+ - Warns about duplicate node name in the same node
93
+ - Reports when deleting a node/property that does not exist
94
+ - Reports generic syntax issues such as missing "," , "}" , "<" , ">" etc...
95
+ - Reports missing values for properties
96
+ - Reports basic CPreprocessor issues such as missing macro name
97
+
98
+ #### Types
99
+
100
+ - Supports standard types as defined in chapter 2 of Devicetree Specification Release v0.4
101
+ - Reports property type mismatch errors
102
+ - Reports prop-encoded-values errors when these need to follow some pattern e.g interrupts
103
+ - 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
104
+ - And more... (See Chapter 2 of Devicetree Specification Release v0.4 https://devicetree.org)
105
+
106
+ ### Document Formatting
107
+
108
+ - Fixes indentation
109
+ - Fixes spacing between label names on assign
110
+ - Fixes spacing between node name and '{'
111
+ - Ensures new line between node/property/keywords. If there is one additional line this is kept; any additional lines are cleaned up.
112
+ - Ensures that composite values have single space between ',' and next value
113
+ - Ensures that Bytestring/prop-encoded-array values have single space between each value
114
+ - Ensures that no space exists between ';' and end of statement
115
+
116
+ ### Completions
117
+
118
+ Completions are context aware of the document state on the line the action is requested.
119
+
120
+ - Node path completion
121
+ - Label reference completion in property assign values
122
+ - Delete Node:
123
+ - Suggests appropriate type e.g. by reference or node name
124
+ - Does not suggest keyword if no delete is possible
125
+ - Delete Property:
126
+ - Suggests property names available in that context
127
+ - Does not suggest keyword if no delete is possible
128
+ - Default values for standard types (e.g state)
129
+
130
+ ### Code Actions
131
+
132
+ - Adds missing syntax e.g. ';', '<', '>', ',' etc...
133
+ - Removes syntactically incorrect spaces:
134
+ - Between node name, '@' and address
135
+ - In node path reference
136
+ - Removes ';' when used without any statement
137
+ - Suggests solutions for incomplete /delete-node/ keywords
138
+ - Suggests solutions for incomplete /delete-property/ keywords
139
+ - Supports SourceFixAll/QuickFixes
140
+
141
+ ### Find Definition
142
+
143
+ - On node name/label reference; will list all the places where the node is altered. /delete-node/ cases are not listed.
144
+ - 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.
145
+
146
+ 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 definiton from under the delete keyword.
147
+
148
+ ### Find Declarations
149
+
150
+ - On node name/label reference; will list the first places where the node is created.
151
+ - 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.
152
+
153
+ 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.
154
+
155
+ ### Find References
156
+
157
+ - On node name/label reference; will list all the places where the node is used by name, label or in some path.
158
+ - On property name; will list all the places where the property referred to including /delete-property/.
159
+
160
+ 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.
161
+
162
+ ### Hover
163
+
164
+ - 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.
165
+
166
+ ### Limitations
167
+
168
+ Parsing will only look at the files the devicetree uses. C header files will not be parsed to keep parsing fast enough. Hence there is no check on whether a macro exists and therefore there is no type checking.
169
+
170
+ ## Bindings
171
+
172
+ 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.
173
+
174
+ ## Refactoring
175
+
176
+ Refactoring is possible on the following elements:
177
+
178
+ - Node names
179
+ - Node labels
180
+ - Propery names
181
+
182
+ 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".
183
+
184
+ ### Road Map
185
+
186
+ - Formatting
187
+ - Clean up trailing white spaces
188
+ - Implement syntax for Ternary operator
189
+ - Implement support #IF and #ELSEIF preprocessors
190
+ - Implement "Device Node Requirements" (chapter 3 - Devicetree Specification Release v0.4)
191
+ - Implement formating on commetent nodes
192
+ - Write more unit tests
193
+ - Let me know what you should be added or changed