|
15 | 15 | -- of the license. -- |
16 | 16 | ----------------------------------------------------------------------------*/ |
17 | 17 |
|
| 18 | +/** |
| 19 | + * Implementation of AdaSyntaxCheckProvider, an extension to the LSP that allows the client to send |
| 20 | + * a request to the server, that checks the validity of some input according to a sert of rules |
| 21 | + */ |
| 22 | + |
18 | 23 | import { LanguageClient } from 'vscode-languageclient/node'; |
19 | 24 |
|
| 25 | +/** |
| 26 | + * Enum with the available grammar rules for Ada. These must match the Ada_Node_Kind_Type literals |
| 27 | + * defined in the Libadalang.Common package, since ALS is expected to parse the |
| 28 | + * AdaSyntaxCheckRequest.rules as an array of Ada_Node_Kind_Types literals. |
| 29 | + * |
| 30 | + * This set is imcomplete and will rules can be added as needed. |
| 31 | + */ |
20 | 32 | export enum AdaGrammarRule { |
21 | 33 | Defining_Id_Rule = 'Defining_Id_Rule', |
22 | 34 | Defining_Id_List_Rule = 'Defining_Id_List_Rule', |
23 | 35 | Param_Spec_Rule = 'Param_Spec_Rule', |
24 | 36 | } |
25 | 37 |
|
| 38 | +/** |
| 39 | + * Structure with the data needed for the request |
| 40 | + * |
| 41 | + * @typeParam input - Input provided by the user |
| 42 | + * @typeParam rules - Array of rules that input will be checked against to |
| 43 | + */ |
26 | 44 | type AdaSyntaxCheckRequest = { |
27 | 45 | input: string; |
28 | 46 | rules: string[]; |
29 | 47 | }; |
30 | 48 |
|
| 49 | +/** |
| 50 | + * Structure with data responsded by the server |
| 51 | + * |
| 52 | + * @typeParam diagnostic - A diagnostic message in case the systax was not valid. undefined if the |
| 53 | + * syntax was valid |
| 54 | + */ |
31 | 55 | type AdaSyntaxCheckResponse = { |
32 | 56 | diagnostic?: string; |
33 | 57 | }; |
34 | 58 |
|
| 59 | +/** |
| 60 | + * Class that implements an a syntax check request as an extension to the LSP |
| 61 | + */ |
35 | 62 | export class AdaSyntaxCheckProvider { |
36 | 63 | private readonly client: LanguageClient; |
37 | 64 | rules: string[]; |
38 | 65 | diagnostic?: string; |
39 | 66 |
|
| 67 | + /** |
| 68 | + * AdaSyntaxCheckProvider constructor |
| 69 | + * |
| 70 | + * @param client - An ALS LanguageClient |
| 71 | + * @param rules - Set of rules used to check an input against |
| 72 | + * @param diagnotic - And optional diagnostic message that overwrites the one sent by the server |
| 73 | + */ |
40 | 74 | constructor(client: LanguageClient, rules: AdaGrammarRule[], diagnotic?: string) { |
41 | 75 | this.client = client; |
42 | 76 | this.rules = rules.map((rule) => rule.toString()); |
43 | 77 | this.diagnostic = diagnotic; |
44 | 78 | } |
45 | 79 |
|
| 80 | + /** |
| 81 | + * Method that uses this.client to send a request to the user with |
| 82 | + * |
| 83 | + * @param input - Input provided by the user |
| 84 | + * @returns A promise that resolves to undefined if the input is syntactically correct, or a |
| 85 | + * string with a human-readable diagnostic message in case it is not. |
| 86 | + */ |
46 | 87 | public sendCheckSyntaxRequest = async (input: string): Promise<undefined | string> => { |
47 | 88 | const method = '$/alsCheckSyntax'; |
48 | 89 |
|
|
0 commit comments