Skip to content

Commit dfb1456

Browse files
committed
Merge branch 'topic/lsp_gen' into 'master'
Add a tool to generate LSP 3.17 code See merge request eng/ide/ada_language_server!1275
2 parents c583766 + 95b3883 commit dfb1456

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+29471
-0
lines changed

doc/metaModel.json

Lines changed: 14316 additions & 0 deletions
Large diffs are not rendered by default.

doc/metaModel.schema.json

Lines changed: 688 additions & 0 deletions
Large diffs are not rendered by default.

gnat/lsp_gen.gpr

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2023, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
with "vss_text";
19+
with "vss_json";
20+
21+
project LSP_Gen is
22+
23+
type Any_Build_Mode is (
24+
"prod",
25+
-- Produce efficient code to be used in production and don't treat
26+
-- warnings as errors.
27+
28+
"dev"
29+
-- Produce easy-to-debug code with extra checks. Treat warnings as
30+
-- errors.
31+
);
32+
Build_Mode : Any_Build_Mode := external ("BUILD_MODE", "dev");
33+
34+
Superproject := external ("SUPERPROJECT", "");
35+
36+
for Source_Dirs use ("../source/lsp_gen", "../source/lsp_gen/generated");
37+
for Object_Dir use "../.obj/" & Superproject & "/lsp_gen";
38+
for Main use ("lsp_gen-run.adb");
39+
40+
-- Compute the list of default switches to build Ada unit
41+
42+
Common_Ada_Switches := (
43+
-- Generate debug information even in production: this is useful to
44+
-- get meaningful tracebacks.
45+
"-g",
46+
47+
-- Compile with "-gnatX" to support the "[]" syntax for array
48+
-- aggregates: this is the common ground between all compilers
49+
-- commonly used to build the language server.
50+
"-gnatX");
51+
52+
Ada_Switches := ();
53+
case Build_Mode is
54+
when "prod" =>
55+
Ada_Switches := (
56+
-- Compile with optimizations
57+
"-O2"
58+
);
59+
60+
when "dev" =>
61+
Ada_Switches := (
62+
-- Compile with no optimization and with debug information to ease
63+
-- investigation in debuggers.
64+
"-O0",
65+
66+
-- Enable all warnings and GNAT stylechecks (plus O: check for
67+
-- overriding indicators).
68+
"-gnatwaJ", "-gnatygO",
69+
70+
-- Enable assertions and all validity checking options
71+
"-gnata", "-gnatVa",
72+
73+
-- Enable stack overflow checks
74+
"-fstack-check"
75+
);
76+
end case;
77+
78+
package Compiler is
79+
for Default_Switches ("Ada") use Common_Ada_Switches & Ada_Switches;
80+
for Local_Configuration_Pragmas use "gnat.adc";
81+
end Compiler;
82+
83+
package Binder is
84+
for Switches ("ada") use ("-E");
85+
end Binder;
86+
87+
package Pretty_Printer is
88+
for Default_Switches ("ada") use
89+
("--no-align-modes",
90+
"--no-separate-is",
91+
"--comments-fill",
92+
"--call-threshold=1",
93+
"--par-threshold=2",
94+
"--vertical-named-aggregates",
95+
"--wide-character-encoding=8");
96+
end Pretty_Printer;
97+
98+
end LSP_Gen;

source/lsp_gen/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
GEN_JSON = gen_json
2+
OUT_DIR = ./generated
3+
GNATPP_OPTS = -P ../../gnat/lsp_gen.gpr
4+
DOC = ../../doc
5+
6+
all: create pretty build generate
7+
8+
create: ${DOC}/metaModel.schema.json header.adt
9+
${GEN_JSON} \
10+
--root-package LSP_Gen.Entities --enum-package Enum \
11+
--header-file header.adt \
12+
--holder "#/definitions/ArrayType:element" \
13+
--holder "#/definitions/MapType:value" \
14+
${DOC}/metaModel.schema.json > ada.txt
15+
gnatchop -w ada.txt ${OUT_DIR}
16+
17+
pretty:
18+
gnatpp ${GNATPP_OPTS} ${OUT_DIR}/*.ad[sb]
19+
20+
build: pretty
21+
gprbuild ${GNATPP_OPTS}
22+
23+
generate: build
24+
../../.obj/gs/lsp_gen/lsp_gen-run ${DOC}/metaModel.json config/3_17.json5 > /tmp/aaa.txt

source/lsp_gen/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Requirements
2+
3+
Have a working Ada environment (with `gnatchop`, `gnatpp` binaries) and
4+
install the program with `alire`:
5+
6+
```shell
7+
git clone https://github.com/AdaCore/VSS.git
8+
cd VSS/tools/json_schema
9+
alr build
10+
```
11+
12+
# How to use
13+
14+
One have to be in the `lsp_gen` directory and and have `gnatpp`, `gnatchop`, `gen_json` in the `PATH`.
15+
16+
From there one can generate the code with a single `make` command.

source/lsp_gen/config/3_17.json5

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
// These lines will be put as a header into each Ada file
3+
"license header": [
4+
"",
5+
"Copyright (C) <YEAR>, <COPYRIGHT HOLDER>",
6+
"",
7+
"SPDX-License-Identifier: MIT",
8+
""
9+
],
10+
11+
// Notification
12+
13+
"$/cancelRequest": {
14+
"from": "both"
15+
},
16+
"$/logTrace": {
17+
"from": "server"
18+
},
19+
"$/progress": {
20+
"from": "both"
21+
},
22+
"$/setTrace": {
23+
"from": "client"
24+
},
25+
"exit": {
26+
"from": "client",
27+
"name": "Exits"
28+
},
29+
"initialized": {
30+
"from": "client"
31+
},
32+
"notebookDocument/didChange": {
33+
"from": "client",
34+
"name": "DidChangeNotebook"
35+
},
36+
"notebookDocument/didClose": {
37+
"from": "client",
38+
"name": "DidCloseNotebook"
39+
},
40+
"notebookDocument/didOpen": {
41+
"from": "client",
42+
"name": "DidOpenNotebook"
43+
},
44+
"notebookDocument/didSave": {
45+
"from": "client",
46+
"name": "DidSaveNotebook"
47+
},
48+
"telemetry/event": {
49+
"from": "server"
50+
},
51+
"textDocument/didChange": {
52+
"from": "client"
53+
},
54+
"textDocument/didClose": {
55+
"from": "client"
56+
},
57+
"textDocument/didOpen": {
58+
"from": "client"
59+
},
60+
"textDocument/didSave": {
61+
"from": "client"
62+
},
63+
"textDocument/publishDiagnostics": {
64+
"from": "server"
65+
},
66+
"textDocument/willSave": {
67+
"from": "client"
68+
},
69+
"window/logMessage": {
70+
"from": "server"
71+
},
72+
"window/showMessage": {
73+
"from": "server"
74+
},
75+
"window/workDoneProgress/cancel": {
76+
"from": "client"
77+
},
78+
"workspace/didChangeConfiguration": {
79+
"from": "client"
80+
},
81+
"workspace/didChangeWatchedFiles": {
82+
"from": "client"
83+
},
84+
"workspace/didChangeWorkspaceFolders": {
85+
"from": "client"
86+
},
87+
"workspace/didCreateFiles": {
88+
"from": "client"
89+
},
90+
"workspace/didDeleteFiles": {
91+
"from": "client"
92+
},
93+
"workspace/didRenameFiles": {
94+
"from": "client"
95+
},
96+
// Requests:
97+
98+
// "callHierarchy/incomingCalls"
99+
// "callHierarchy/outgoingCalls"
100+
"client/registerCapability": {
101+
"from": "server"
102+
},
103+
"client/unregisterCapability": {
104+
"from": "server"
105+
},
106+
"codeAction/resolve": {
107+
"from": "client",
108+
"name": "Code_Action_Resolve"
109+
},
110+
"codeLens/resolve": {
111+
"from": "client",
112+
"name": "Code_Lens_Resolve"
113+
},
114+
"completionItem/resolve": {
115+
"from": "client",
116+
"name": "Completion_Resolve"
117+
},
118+
"documentLink/resolve": {
119+
"from": "client",
120+
"name": "Link_Resolve"
121+
},
122+
// "initialize"
123+
"inlayHint/resolve": {
124+
"from": "client",
125+
"name": "Inlay_Resolve"
126+
},
127+
// "shutdown"
128+
// "textDocument/codeAction"
129+
// "textDocument/codeLens"
130+
// "textDocument/colorPresentation"
131+
// "textDocument/completion"
132+
// "textDocument/declaration"
133+
// "textDocument/definition"
134+
// "textDocument/diagnostic"
135+
// "textDocument/documentColor"
136+
// "textDocument/documentHighlight"
137+
// "textDocument/documentLink"
138+
// "textDocument/documentSymbol"
139+
// "textDocument/foldingRange"
140+
// "textDocument/formatting"
141+
// "textDocument/hover"
142+
// "textDocument/implementation"
143+
// "textDocument/inlayHint"
144+
// "textDocument/inlineValue"
145+
// "textDocument/linkedEditingRange"
146+
// "textDocument/moniker"
147+
// "textDocument/onTypeFormatting"
148+
// "textDocument/prepareCallHierarchy"
149+
// "textDocument/prepareRename"
150+
// "textDocument/prepareTypeHierarchy"
151+
// "textDocument/rangeFormatting"
152+
// "textDocument/references"
153+
// "textDocument/rename"
154+
// "textDocument/selectionRange"
155+
// "textDocument/semanticTokens/full"
156+
"textDocument/semanticTokens/full/delta": {
157+
"from": "client",
158+
"name": "Tokens_Delta"
159+
},
160+
"textDocument/semanticTokens/range": {
161+
"from": "client",
162+
"name": "Tokens_Range"
163+
},
164+
// "textDocument/signatureHelp"
165+
// "textDocument/typeDefinition"
166+
// "textDocument/willSaveWaitUntil"
167+
// "typeHierarchy/subtypes"
168+
// "typeHierarchy/supertypes"
169+
"window/showDocument": {
170+
"from": "server"
171+
},
172+
"window/showMessageRequest": {
173+
"from": "server"
174+
},
175+
"window/workDoneProgress/create": {
176+
"from": "server",
177+
"name": "Progress_Create"
178+
},
179+
"workspace/applyEdit": {
180+
"from": "server"
181+
},
182+
"workspace/codeLens/refresh": {
183+
"from": "server",
184+
"name": "Code_Lens_Refresh"
185+
},
186+
"workspace/configuration": {
187+
"from": "server"
188+
},
189+
"workspace/diagnostic": {
190+
"from": "client",
191+
"name": "Workspace_Diagnostic"
192+
},
193+
"workspace/diagnostic/refresh": {
194+
"from": "server",
195+
"name": "Diagnostic_Refresh"
196+
},
197+
// "workspace/executeCommand"
198+
"workspace/inlayHint/refresh": {
199+
"from": "server",
200+
"name": "Inlay_Refresh"
201+
},
202+
"workspace/inlineValue/refresh": {
203+
"from": "server",
204+
"name": "Inline_Refresh"
205+
},
206+
"workspace/semanticTokens/refresh": {
207+
"from": "server",
208+
"name": "Tokens_Refresh"
209+
},
210+
// "workspace/symbol"
211+
"workspaceSymbol/resolve": {
212+
"from": "client",
213+
"name": "Symbol_Resolve"
214+
},
215+
// "workspace/willCreateFiles"
216+
// "workspace/willDeleteFiles"
217+
// "workspace/willRenameFiles"
218+
"workspace/workspaceFolders": {
219+
"from": "server"
220+
}
221+
222+
}

0 commit comments

Comments
 (0)