astn 0.110.15 → 1.20.5
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/.eslintignore +5 -0
- package/.eslintrc.js +20 -0
- package/.vscode/extensions.json +9 -0
- package/.vscode/launch.json +39 -0
- package/.vscode/settings.json +8 -0
- package/.vscode/tasks.json +33 -0
- package/.vscodeignore +15 -0
- package/LICENSE.md +204 -0
- package/README.md +3 -410
- package/backend/package-lock.json +123 -0
- package/backend/package.json +6 -0
- package/backend/src/index.ts +133 -0
- package/backend/tsconfig.json +16 -0
- package/client/package-lock.json +581 -0
- package/client/package.json +23 -0
- package/client/src/extension.ts +249 -0
- package/client/src/test/completion.test.ts +43 -0
- package/client/src/test/diagnostics.test.ts +41 -0
- package/client/src/test/helper.ts +47 -0
- package/client/src/test/index.ts +43 -0
- package/client/src/test/runTest.ts +27 -0
- package/client/testFixture/diagnostics.txt +1 -0
- package/client/tsconfig.json +12 -0
- package/client/tsconfig.tsbuildinfo +1 -0
- package/development.md +12 -0
- package/images/icon.png +0 -0
- package/language-configuration.json +36 -0
- package/package.json +102 -58
- package/scripts/e2e.sh +6 -0
- package/server/package-lock.json +127 -0
- package/server/package.json +22 -0
- package/server/src/backend.ts +53 -0
- package/server/src/backendapi.ts +66 -0
- package/server/src/server.ts +296 -0
- package/server/tsconfig.json +14 -0
- package/server/tsconfig.tsbuildinfo +1 -0
- package/syntaxes/astn.tmLanguage.json +320 -0
- package/tsconfig.json +21 -0
- package/LICENSE +0 -17
- package/dist/bin/convert_to_json.d.ts +0 -2
- package/dist/bin/convert_to_json.js +0 -63
- package/dist/bin/validate_astn.d.ts +0 -2
- package/dist/bin/validate_astn.js +0 -58
- package/dist/generated/generic/resolve.d.ts +0 -90
- package/dist/generated/generic/resolve.js +0 -259
- package/dist/generated/implementation/schemas/ast/migration_boilerplate.d.ts +0 -13
- package/dist/generated/implementation/schemas/ast/migration_boilerplate.js +0 -174
- package/dist/generated/implementation/schemas/ide/migration_boilerplate.d.ts +0 -2
- package/dist/generated/implementation/schemas/ide/migration_boilerplate.js +0 -56
- package/dist/generated/implementation/schemas/parse_result/migration_boilerplate.d.ts +0 -6
- package/dist/generated/implementation/schemas/parse_result/migration_boilerplate.js +0 -136
- package/dist/generated/implementation/schemas/target/migration_boilerplate.d.ts +0 -3
- package/dist/generated/implementation/schemas/target/migration_boilerplate.js +0 -73
- package/dist/generated/implementation/schemas/target_json/migration_boilerplate.d.ts +0 -3
- package/dist/generated/implementation/schemas/target_json/migration_boilerplate.js +0 -67
- package/dist/generated/interface/core/poormans_parser.d.ts +0 -184
- package/dist/generated/interface/core/poormans_parser.js +0 -3
- package/dist/generated/interface/core/resolved.d.ts +0 -100
- package/dist/generated/interface/core/resolved.js +0 -3
- package/dist/generated/interface/core/unresolved.d.ts +0 -35
- package/dist/generated/interface/core/unresolved.js +0 -3
- package/dist/generated/interface/schemas/ast/migration_boilerplate.d.ts +0 -266
- package/dist/generated/interface/schemas/ast/migration_boilerplate.js +0 -3
- package/dist/generated/interface/schemas/ast/poormans_parser.d.ts +0 -1087
- package/dist/generated/interface/schemas/ast/poormans_parser.js +0 -3
- package/dist/generated/interface/schemas/ast/resolved.d.ts +0 -1087
- package/dist/generated/interface/schemas/ast/resolved.js +0 -3
- package/dist/generated/interface/schemas/ast/unresolved.d.ts +0 -1087
- package/dist/generated/interface/schemas/ast/unresolved.js +0 -3
- package/dist/generated/interface/schemas/ide/migration_boilerplate.d.ts +0 -24
- package/dist/generated/interface/schemas/ide/migration_boilerplate.js +0 -3
- package/dist/generated/interface/schemas/ide/poormans_parser.d.ts +0 -161
- package/dist/generated/interface/schemas/ide/poormans_parser.js +0 -3
- package/dist/generated/interface/schemas/ide/resolved.d.ts +0 -161
- package/dist/generated/interface/schemas/ide/resolved.js +0 -3
- package/dist/generated/interface/schemas/ide/unresolved.d.ts +0 -161
- package/dist/generated/interface/schemas/ide/unresolved.js +0 -3
- package/dist/generated/interface/schemas/parse_result/migration_boilerplate.d.ts +0 -112
- package/dist/generated/interface/schemas/parse_result/migration_boilerplate.js +0 -3
- package/dist/generated/interface/schemas/parse_result/poormans_parser.d.ts +0 -416
- package/dist/generated/interface/schemas/parse_result/poormans_parser.js +0 -3
- package/dist/generated/interface/schemas/parse_result/resolved.d.ts +0 -416
- package/dist/generated/interface/schemas/parse_result/resolved.js +0 -3
- package/dist/generated/interface/schemas/parse_result/unresolved.d.ts +0 -416
- package/dist/generated/interface/schemas/parse_result/unresolved.js +0 -3
- package/dist/generated/interface/schemas/target/migration_boilerplate.d.ts +0 -46
- package/dist/generated/interface/schemas/target/migration_boilerplate.js +0 -3
- package/dist/generated/interface/schemas/target/poormans_parser.d.ts +0 -186
- package/dist/generated/interface/schemas/target/poormans_parser.js +0 -3
- package/dist/generated/interface/schemas/target/resolved.d.ts +0 -186
- package/dist/generated/interface/schemas/target/resolved.js +0 -3
- package/dist/generated/interface/schemas/target/unresolved.d.ts +0 -186
- package/dist/generated/interface/schemas/target/unresolved.js +0 -3
- package/dist/generated/interface/schemas/target_json/migration_boilerplate.d.ts +0 -46
- package/dist/generated/interface/schemas/target_json/migration_boilerplate.js +0 -3
- package/dist/generated/interface/schemas/target_json/poormans_parser.d.ts +0 -169
- package/dist/generated/interface/schemas/target_json/poormans_parser.js +0 -3
- package/dist/generated/interface/schemas/target_json/resolved.d.ts +0 -169
- package/dist/generated/interface/schemas/target_json/resolved.js +0 -3
- package/dist/generated/interface/schemas/target_json/unresolved.d.ts +0 -169
- package/dist/generated/interface/schemas/target_json/unresolved.js +0 -3
- package/dist/globals.d.ts +0 -24
- package/dist/globals.js +0 -2
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -43
- package/dist/lib/globals.d.ts +0 -24
- package/dist/lib/globals.js +0 -2
- package/dist/lib/transformations/create_error_message.d.ts +0 -5
- package/dist/lib/transformations/create_error_message.js +0 -89
- package/dist/lib/transformations/format.d.ts +0 -42
- package/dist/lib/transformations/format.js +0 -166
- package/dist/lib/transformations/fountain_pen/astn.d.ts +0 -11
- package/dist/lib/transformations/fountain_pen/astn.js +0 -156
- package/dist/lib/transformations/fountain_pen/json.d.ts +0 -4
- package/dist/lib/transformations/fountain_pen/json.js +0 -113
- package/dist/lib/transformations/parse.d.ts +0 -11
- package/dist/lib/transformations/parse.js +0 -257
- package/dist/lib/transformations/parse_generic.d.ts +0 -43
- package/dist/lib/transformations/parse_generic.js +0 -644
- package/dist/parse/parse.d.ts +0 -11
- package/dist/parse/parse.js +0 -267
- package/dist/parse/parse_generic.d.ts +0 -43
- package/dist/parse/parse_generic.js +0 -656
- package/dist/serializers/astn.js +0 -28
- package/dist/serializers/json.d.ts +0 -5
- package/dist/serializers/json.js +0 -46
- package/dist/serializers/parse_result.d.ts +0 -5
- package/dist/serializers/parse_result.js +0 -99
- package/dist/transformations/ast/ide.d.ts +0 -42
- package/dist/transformations/ast/ide.js +0 -176
- package/dist/transformations/ast/json_target.d.ts +0 -6
- package/dist/transformations/ast/json_target.js +0 -88
- package/dist/transformations/create_error_message.d.ts +0 -5
- package/dist/transformations/create_error_message.js +0 -89
- package/dist/transformations/format.d.ts +0 -42
- package/dist/transformations/format.js +0 -166
- package/dist/transformations/fountain_pen/astn.d.ts +0 -11
- package/dist/transformations/fountain_pen/astn.js +0 -166
- package/dist/transformations/fountain_pen/json.d.ts +0 -4
- package/dist/transformations/fountain_pen/json.js +0 -123
- package/dist/transformations/parse.d.ts +0 -11
- package/dist/transformations/parse.js +0 -257
- package/dist/transformations/parse_generic.d.ts +0 -43
- package/dist/transformations/parse_generic.js +0 -644
- package/dist/transformations/target/fountain_pen/astn.d.ts +0 -11
- package/dist/transformations/target/fountain_pen/astn.js +0 -156
- package/dist/transformations/target/fountain_pen/json.d.ts +0 -4
- package/dist/transformations/target/fountain_pen/json.js +0 -113
- package/dist/transformations/target/fountain_pen_block.d.ts +0 -11
- package/dist/transformations/target/fountain_pen_block.js +0 -166
- package/dist/transformations/target_json/fountain_pen_block.d.ts +0 -4
- package/dist/transformations/target_json/fountain_pen_block.js +0 -101
- package/documentation/railroad_diagram/diagram/apostrophed_string.png +0 -0
- package/documentation/railroad_diagram/diagram/astn_document.png +0 -0
- package/documentation/railroad_diagram/diagram/backticked_string.png +0 -0
- package/documentation/railroad_diagram/diagram/comment.png +0 -0
- package/documentation/railroad_diagram/diagram/concise_group.png +0 -0
- package/documentation/railroad_diagram/diagram/content.png +0 -0
- package/documentation/railroad_diagram/diagram/dictionary.png +0 -0
- package/documentation/railroad_diagram/diagram/elements.png +0 -0
- package/documentation/railroad_diagram/diagram/escaped_character.png +0 -0
- package/documentation/railroad_diagram/diagram/four_hexadecimal_digits.png +0 -0
- package/documentation/railroad_diagram/diagram/header.png +0 -0
- package/documentation/railroad_diagram/diagram/hexadecimal_digit.png +0 -0
- package/documentation/railroad_diagram/diagram/ignorable.png +0 -0
- package/documentation/railroad_diagram/diagram/include.png +0 -0
- package/documentation/railroad_diagram/diagram/key_value_pairs.png +0 -0
- package/documentation/railroad_diagram/diagram/line_comment.png +0 -0
- package/documentation/railroad_diagram/diagram/list.png +0 -0
- package/documentation/railroad_diagram/diagram/newline_character.png +0 -0
- package/documentation/railroad_diagram/diagram/normal_character.png +0 -0
- package/documentation/railroad_diagram/diagram/normal_or_newline_character.png +0 -0
- package/documentation/railroad_diagram/diagram/quoted_string.png +0 -0
- package/documentation/railroad_diagram/diagram/rr-2.5.png +0 -0
- package/documentation/railroad_diagram/diagram/set_optional_value.png +0 -0
- package/documentation/railroad_diagram/diagram/string.png +0 -0
- package/documentation/railroad_diagram/diagram/string_content_character.png +0 -0
- package/documentation/railroad_diagram/diagram/tagged_value.png +0 -0
- package/documentation/railroad_diagram/diagram/traditional_comment.png +0 -0
- package/documentation/railroad_diagram/diagram/undelimited_string.png +0 -0
- package/documentation/railroad_diagram/diagram/value.png +0 -0
- package/documentation/railroad_diagram/diagram/verbose_group.png +0 -0
- package/documentation/railroad_diagram/diagram/whitespace.png +0 -0
- package/documentation/railroad_diagram/index.md +0 -425
- /package/{dist/serializers/astn.d.ts → client/testFixture/completion.txt} +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
* ------------------------------------------------------------------------------------------ */
|
|
5
|
+
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { workspace, ExtensionContext } from 'vscode';
|
|
8
|
+
|
|
9
|
+
import * as backend from "../../backend/dist"
|
|
10
|
+
|
|
11
|
+
import * as fs from "fs"
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
LanguageClient,
|
|
15
|
+
LanguageClientOptions,
|
|
16
|
+
ServerOptions,
|
|
17
|
+
TransportKind
|
|
18
|
+
} from 'vscode-languageclient/node';
|
|
19
|
+
|
|
20
|
+
import * as vscode from 'vscode'
|
|
21
|
+
|
|
22
|
+
let client: LanguageClient;
|
|
23
|
+
|
|
24
|
+
const create_vscode_position = (position: backend.Relative_Location): vscode.Position => {
|
|
25
|
+
return new vscode.Position(position.line, position.column);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const create_vscode_range = (backend_range: backend.Relative_Range): vscode.Range => {
|
|
29
|
+
return new vscode.Range(create_vscode_position(backend_range.start), create_vscode_position(backend_range.end));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
function create_backend_position(document: vscode.TextDocument, offset: number): backend.Relative_Location {
|
|
34
|
+
const x = document.positionAt(offset)
|
|
35
|
+
return { line: x.line, column: x.character }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// function create(document: vscode.TextDocument, range: backend.Range) {
|
|
39
|
+
|
|
40
|
+
// //return new vscode.Range(convertLocation(document, range.start), convertLocation(document, atl.init().getEndLocationFromRange(range)))
|
|
41
|
+
// return new vscode.Range(create_backend_position(document, range.start), create_backend_position(document, range.end))
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export function activate(context: ExtensionContext) {
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
const disposable = vscode.commands.registerCommand('astn.save_as_json', () => {
|
|
51
|
+
vscode.window.showInformationMessage('Save as JSON!');
|
|
52
|
+
|
|
53
|
+
const editor = vscode.window.activeTextEditor;
|
|
54
|
+
if (!editor) {
|
|
55
|
+
vscode.window.showInformationMessage('Open an ASTN file first to convert to JSON');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const document = editor.document;
|
|
60
|
+
const text = document.getText();
|
|
61
|
+
|
|
62
|
+
const activeUri = vscode.window.activeTextEditor.document.uri;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const result = backend.convert_to_json(text);
|
|
66
|
+
if (result === null) {
|
|
67
|
+
vscode.window.showErrorMessage("Cannot save as JSON because the file is not valid ASTN.");
|
|
68
|
+
return;
|
|
69
|
+
} else {
|
|
70
|
+
|
|
71
|
+
vscode.window.showSaveDialog({}).then(fileInfos => {
|
|
72
|
+
if (result !== null) {
|
|
73
|
+
fs.writeFileSync(fileInfos.path, result, 'utf8');
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
context.subscriptions.push(disposable);
|
|
82
|
+
}
|
|
83
|
+
{
|
|
84
|
+
const disposable = vscode.commands.registerCommand('astn.sort_alphabetically', () => {
|
|
85
|
+
|
|
86
|
+
const editor = vscode.window.activeTextEditor;
|
|
87
|
+
if (!editor) {
|
|
88
|
+
vscode.window.showInformationMessage('Open an ASTN file first to sort alphabetically');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const document = editor.document;
|
|
93
|
+
const text = document.getText();
|
|
94
|
+
const position = editor.selection.active
|
|
95
|
+
|
|
96
|
+
const activeUri = vscode.window.activeTextEditor.document.uri;
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
const result = backend.sort_alphabetically(text, { 'position': { line: position.line, column: position.character } });
|
|
100
|
+
result.transform(
|
|
101
|
+
($) => {
|
|
102
|
+
editor.edit(editBuilder => {
|
|
103
|
+
editBuilder.replace(create_vscode_range($.range), $.text);
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
() => {
|
|
107
|
+
vscode.window.showErrorMessage("Sorting failed because the file is not valid ASTN.");
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
context.subscriptions.push(disposable);
|
|
114
|
+
}
|
|
115
|
+
{
|
|
116
|
+
const disposable = vscode.commands.registerCommand('astn.convert_to_json', () => {
|
|
117
|
+
vscode.window.showInformationMessage('Convert to JSON!');
|
|
118
|
+
|
|
119
|
+
const editor = vscode.window.activeTextEditor;
|
|
120
|
+
if (!editor) {
|
|
121
|
+
vscode.window.showInformationMessage('Open an ASTN file first to save as JSON');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const document = editor.document;
|
|
126
|
+
const text = document.getText();
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
const result = backend.convert_to_json(text);
|
|
131
|
+
if (result === null) {
|
|
132
|
+
vscode.window.showErrorMessage("Conversion to JSON failed because the file is not valid ASTN.");
|
|
133
|
+
return;
|
|
134
|
+
} else {
|
|
135
|
+
editor.edit(($) => {
|
|
136
|
+
$.replace(
|
|
137
|
+
new vscode.Range(
|
|
138
|
+
new vscode.Position(0, 0),
|
|
139
|
+
editor.document.lineAt(editor.document.lineCount - 1).range.end
|
|
140
|
+
),
|
|
141
|
+
result
|
|
142
|
+
)
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
context.subscriptions.push(disposable);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
// The server is implemented in node
|
|
154
|
+
const serverModule = context.asAbsolutePath(
|
|
155
|
+
path.join('server', 'out', 'server.js')
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// If the extension is launched in debug mode then the debug server options are used
|
|
159
|
+
// Otherwise the run options are used
|
|
160
|
+
const serverOptions: ServerOptions = {
|
|
161
|
+
run: { module: serverModule, transport: TransportKind.ipc },
|
|
162
|
+
debug: {
|
|
163
|
+
module: serverModule,
|
|
164
|
+
transport: TransportKind.ipc,
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// Options to control the language client
|
|
169
|
+
const clientOptions: LanguageClientOptions = {
|
|
170
|
+
// Register the server for plain text documents
|
|
171
|
+
documentSelector: [{ scheme: 'file', language: 'astn' }],
|
|
172
|
+
synchronize: {
|
|
173
|
+
// Notify the server about file changes to '.clientrc files contained in the workspace
|
|
174
|
+
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// Create the language client and start the client.
|
|
179
|
+
client = new LanguageClient(
|
|
180
|
+
'ASNTLanguageServer',
|
|
181
|
+
'ASTN Language Server',
|
|
182
|
+
serverOptions,
|
|
183
|
+
clientOptions
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
vscode.languages.registerDocumentFormattingEditProvider('astn', {
|
|
188
|
+
provideDocumentFormattingEdits(document: vscode.TextDocument, options) {
|
|
189
|
+
const edits: vscode.TextEdit[] = [];
|
|
190
|
+
// Read user configuration for formatting
|
|
191
|
+
const config = vscode.workspace.getConfiguration('astn');
|
|
192
|
+
console.log("HIER DAN?")
|
|
193
|
+
const result = backend.format(
|
|
194
|
+
document.getText(),
|
|
195
|
+
{
|
|
196
|
+
'preserve delimiters': config.get<boolean>('format.Preserve Delimiters', false),
|
|
197
|
+
'indent string': config.get<string>('format.Indentation String', ' '),
|
|
198
|
+
'preserve final newline state': config.get<boolean>('format.Preserve Final Newline State', true),
|
|
199
|
+
'preserve commas': config.get<boolean>('format.Preserve Commas', true),
|
|
200
|
+
'insert spaces': options.insertSpaces,
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
switch (result[0]) {
|
|
204
|
+
case 'failure':
|
|
205
|
+
console.error("Formatting failed:", result[1].message);
|
|
206
|
+
vscode.window.showErrorMessage("Formatting failed: " + result[1].message);
|
|
207
|
+
return [];
|
|
208
|
+
case 'success':
|
|
209
|
+
return result[1].__get_raw_copy().map(edit => {
|
|
210
|
+
switch (edit[0]) {
|
|
211
|
+
case 'replace':
|
|
212
|
+
console.log("REPLACE", edit[1].range.start, edit[1].range.end, edit[1].text)
|
|
213
|
+
|
|
214
|
+
return vscode.TextEdit.replace(
|
|
215
|
+
create_vscode_range(edit[1].range),
|
|
216
|
+
edit[1].text
|
|
217
|
+
);
|
|
218
|
+
case 'delete':
|
|
219
|
+
return vscode.TextEdit.delete(
|
|
220
|
+
create_vscode_range(edit[1].range)
|
|
221
|
+
);
|
|
222
|
+
case 'insert':
|
|
223
|
+
return vscode.TextEdit.insert(
|
|
224
|
+
create_vscode_position(edit[1].location),
|
|
225
|
+
edit[1].text
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
default:
|
|
230
|
+
throw new Error("Unknown result type: " + result[0]);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
// Start the client. This will also launch the server
|
|
239
|
+
client.start();
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function deactivate(): Thenable<void> | undefined {
|
|
245
|
+
if (!client) {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
return client.stop();
|
|
249
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
* ------------------------------------------------------------------------------------------ */
|
|
5
|
+
|
|
6
|
+
import * as vscode from 'vscode';
|
|
7
|
+
import * as assert from 'assert';
|
|
8
|
+
import { getDocUri, activate } from './helper';
|
|
9
|
+
|
|
10
|
+
suite('Should do completion', () => {
|
|
11
|
+
const docUri = getDocUri('completion.txt');
|
|
12
|
+
|
|
13
|
+
test('Completes JS/TS in txt file', async () => {
|
|
14
|
+
await testCompletion(docUri, new vscode.Position(0, 0), {
|
|
15
|
+
items: [
|
|
16
|
+
{ label: 'JavaScript', kind: vscode.CompletionItemKind.Text },
|
|
17
|
+
{ label: 'TypeScript', kind: vscode.CompletionItemKind.Text }
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
async function testCompletion(
|
|
24
|
+
docUri: vscode.Uri,
|
|
25
|
+
position: vscode.Position,
|
|
26
|
+
expectedCompletionList: vscode.CompletionList
|
|
27
|
+
) {
|
|
28
|
+
await activate(docUri);
|
|
29
|
+
|
|
30
|
+
// Executing the command `vscode.executeCompletionItemProvider` to simulate triggering completion
|
|
31
|
+
const actualCompletionList = (await vscode.commands.executeCommand(
|
|
32
|
+
'vscode.executeCompletionItemProvider',
|
|
33
|
+
docUri,
|
|
34
|
+
position
|
|
35
|
+
)) as vscode.CompletionList;
|
|
36
|
+
|
|
37
|
+
assert.ok(actualCompletionList.items.length >= 2);
|
|
38
|
+
expectedCompletionList.items.forEach((expectedItem, i) => {
|
|
39
|
+
const actualItem = actualCompletionList.items[i];
|
|
40
|
+
assert.equal(actualItem.label, expectedItem.label);
|
|
41
|
+
assert.equal(actualItem.kind, expectedItem.kind);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
* ------------------------------------------------------------------------------------------ */
|
|
5
|
+
|
|
6
|
+
import * as vscode from 'vscode';
|
|
7
|
+
import * as assert from 'assert';
|
|
8
|
+
import { getDocUri, activate } from './helper';
|
|
9
|
+
|
|
10
|
+
suite('Should get diagnostics', () => {
|
|
11
|
+
const docUri = getDocUri('diagnostics.txt');
|
|
12
|
+
|
|
13
|
+
test('Diagnoses uppercase texts', async () => {
|
|
14
|
+
await testDiagnostics(docUri, [
|
|
15
|
+
{ message: 'ANY is all uppercase.', range: toRange(0, 0, 0, 3), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
|
|
16
|
+
{ message: 'ANY is all uppercase.', range: toRange(0, 14, 0, 17), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
|
|
17
|
+
{ message: 'OS is all uppercase.', range: toRange(0, 18, 0, 20), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' }
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {
|
|
23
|
+
const start = new vscode.Position(sLine, sChar);
|
|
24
|
+
const end = new vscode.Position(eLine, eChar);
|
|
25
|
+
return new vscode.Range(start, end);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {
|
|
29
|
+
await activate(docUri);
|
|
30
|
+
|
|
31
|
+
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
|
|
32
|
+
|
|
33
|
+
assert.equal(actualDiagnostics.length, expectedDiagnostics.length);
|
|
34
|
+
|
|
35
|
+
expectedDiagnostics.forEach((expectedDiagnostic, i) => {
|
|
36
|
+
const actualDiagnostic = actualDiagnostics[i];
|
|
37
|
+
assert.equal(actualDiagnostic.message, expectedDiagnostic.message);
|
|
38
|
+
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range);
|
|
39
|
+
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
* ------------------------------------------------------------------------------------------ */
|
|
5
|
+
|
|
6
|
+
import * as vscode from 'vscode';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
|
|
9
|
+
export let doc: vscode.TextDocument;
|
|
10
|
+
export let editor: vscode.TextEditor;
|
|
11
|
+
export let documentEol: string;
|
|
12
|
+
export let platformEol: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Activates the vscode.lsp-sample extension
|
|
16
|
+
*/
|
|
17
|
+
export async function activate(docUri: vscode.Uri) {
|
|
18
|
+
// The extensionId is `publisher.name` from package.json
|
|
19
|
+
const ext = vscode.extensions.getExtension('vscode-samples.lsp-sample')!;
|
|
20
|
+
await ext.activate();
|
|
21
|
+
try {
|
|
22
|
+
doc = await vscode.workspace.openTextDocument(docUri);
|
|
23
|
+
editor = await vscode.window.showTextDocument(doc);
|
|
24
|
+
await sleep(2000); // Wait for server activation
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function sleep(ms: number) {
|
|
31
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const getDocPath = (p: string) => {
|
|
35
|
+
return path.resolve(__dirname, '../../testFixture', p);
|
|
36
|
+
};
|
|
37
|
+
export const getDocUri = (p: string) => {
|
|
38
|
+
return vscode.Uri.file(getDocPath(p));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export async function setTestContent(content: string): Promise<boolean> {
|
|
42
|
+
const all = new vscode.Range(
|
|
43
|
+
doc.positionAt(0),
|
|
44
|
+
doc.positionAt(doc.getText().length)
|
|
45
|
+
);
|
|
46
|
+
return editor.edit(eb => eb.replace(all, content));
|
|
47
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
* ------------------------------------------------------------------------------------------ */
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import * as Mocha from 'mocha';
|
|
7
|
+
import * as glob from 'glob';
|
|
8
|
+
|
|
9
|
+
export function run(): Promise<void> {
|
|
10
|
+
// Create the mocha test
|
|
11
|
+
const mocha = new Mocha({
|
|
12
|
+
ui: 'tdd',
|
|
13
|
+
color: true
|
|
14
|
+
});
|
|
15
|
+
mocha.timeout(100000);
|
|
16
|
+
|
|
17
|
+
const testsRoot = __dirname;
|
|
18
|
+
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
glob('**.test.js', { cwd: testsRoot }, (err, files) => {
|
|
21
|
+
if (err) {
|
|
22
|
+
return reject(err);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Add files to the test suite
|
|
26
|
+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
// Run the mocha test
|
|
30
|
+
mocha.run(failures => {
|
|
31
|
+
if (failures > 0) {
|
|
32
|
+
reject(new Error(`${failures} tests failed.`));
|
|
33
|
+
} else {
|
|
34
|
+
resolve();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error(err);
|
|
39
|
+
reject(err);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
|
|
7
|
+
import { runTests } from '@vscode/test-electron';
|
|
8
|
+
|
|
9
|
+
async function sibling(name: string) {
|
|
10
|
+
try {
|
|
11
|
+
// The folder containing the Extension Manifest package.json
|
|
12
|
+
// Passed to `--extensionDevelopmentPath`
|
|
13
|
+
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
|
|
14
|
+
|
|
15
|
+
// The path to test runner
|
|
16
|
+
// Passed to --extensionTestsPath
|
|
17
|
+
const extensionTestsPath = path.resolve(__dirname, './index');
|
|
18
|
+
|
|
19
|
+
// Download VS Code, unzip it and run the integration test
|
|
20
|
+
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error('Failed to run tests');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
sibling("main");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ANY browsers, ANY OS.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/extension.ts","./src/test/completion.test.ts","./src/test/diagnostics.test.ts","./src/test/helper.ts","./src/test/index.ts","./src/test/runTest.ts"],"errors":true,"version":"5.6.3"}
|
package/development.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
## Running the Sample
|
|
3
|
+
|
|
4
|
+
- Run `npm install` in this folder. This installs all necessary npm modules in both the client and server folder
|
|
5
|
+
- Open VS Code on this folder.
|
|
6
|
+
- Press Ctrl+Shift+B to start compiling the client and server in [watch mode](https://code.visualstudio.com/docs/editor/tasks#:~:text=The%20first%20entry%20executes,the%20HelloWorld.js%20file.).
|
|
7
|
+
- Switch to the Run and Debug View in the Sidebar (Ctrl+Shift+D).
|
|
8
|
+
- Select `Launch Client` from the drop down (if it is not already).
|
|
9
|
+
- Press ▷ to run the launch config (F5).
|
|
10
|
+
- In the [Extension Development Host](https://code.visualstudio.com/api/get-started/your-first-extension#:~:text=Then%2C%20inside%20the%20editor%2C%20press%20F5.%20This%20will%20compile%20and%20run%20the%20extension%20in%20a%20new%20Extension%20Development%20Host%20window.) instance of VSCode, open a document in 'plain text' language mode.
|
|
11
|
+
- Type `j` or `t` to see `Javascript` and `TypeScript` completion.
|
|
12
|
+
- Enter text content such as `AAA aaa BBB`. The extension will emit diagnostics for all words in all-uppercase.
|
package/images/icon.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"comments": {
|
|
3
|
+
// symbol used for single line comment. Remove this entry if your language does not support line comments
|
|
4
|
+
"lineComment": "//",
|
|
5
|
+
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
|
|
6
|
+
"blockComment": [ "/*", "*/" ]
|
|
7
|
+
},
|
|
8
|
+
// symbols used as brackets
|
|
9
|
+
"brackets": [
|
|
10
|
+
["[", "]"],
|
|
11
|
+
["<", ">"],
|
|
12
|
+
["{", "}"],
|
|
13
|
+
["(", ")"],
|
|
14
|
+
// ["`", "`"]
|
|
15
|
+
],
|
|
16
|
+
// symbols that are auto closed when typing
|
|
17
|
+
"autoClosingPairs": [
|
|
18
|
+
["[", "]"],
|
|
19
|
+
["<", ">"],
|
|
20
|
+
["{", "}"],
|
|
21
|
+
["(", ")"],
|
|
22
|
+
["\"", "\""],
|
|
23
|
+
["'", "'"],
|
|
24
|
+
["`", "`"]
|
|
25
|
+
],
|
|
26
|
+
// symbols that can be used to surround a selection
|
|
27
|
+
"surroundingPairs": [
|
|
28
|
+
["[", "]"],
|
|
29
|
+
["<", ">"],
|
|
30
|
+
["{", "}"],
|
|
31
|
+
["(", ")"],
|
|
32
|
+
["\"", "\""],
|
|
33
|
+
["'", "'"],
|
|
34
|
+
["`", "`"]
|
|
35
|
+
]
|
|
36
|
+
}
|