Skip to content

Commit 492db96

Browse files
committed
S314-015 Added documentation using TSDoc format
1 parent c45c357 commit 492db96

File tree

6 files changed

+101
-7
lines changed

6 files changed

+101
-7
lines changed

integration/vscode/ada/.eslintrc.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
},
1616
"project": "tsconfig.json"
1717
},
18+
"plugins": [
19+
"@typescript-eslint/eslint-plugin",
20+
"eslint-plugin-tsdoc"
21+
],
1822
"extends": [
1923
"eslint:recommended",
2024
"plugin:@typescript-eslint/recommended",
@@ -24,5 +28,15 @@
2428
"ignorePatterns": [
2529
"out",
2630
"**/*.d.ts"
27-
]
28-
}
31+
],
32+
"rules": {
33+
"tsdoc/syntax": "warn",
34+
"max-len": [
35+
"warn",
36+
{
37+
"code": 100,
38+
"ignoreUrls": true
39+
}
40+
]
41+
}
42+
}

integration/vscode/ada/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
"eslint": "^7.30.0",
252252
"eslint-config-prettier": "^8.3.0",
253253
"eslint-plugin-prettier": "^3.4.0",
254+
"eslint-plugin-tsdoc": "^0.2.14",
254255
"glob": "^7.1.7",
255256
"mocha": "^9.0.2",
256257
"prettier": "^2.3.2",
@@ -272,4 +273,4 @@
272273
"vscode-languageclient": "^7.0.0",
273274
"ws": "^7.5.2"
274275
}
275-
}
276+
}

integration/vscode/ada/src/alsExecuteCommand.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,37 @@
1515
-- of the license. --
1616
----------------------------------------------------------------------------*/
1717

18+
/**
19+
* Implementation of a Middleware.executeCommand that intercepts and executes commands
20+
*/
21+
1822
import { ExecuteCommandSignature } from 'vscode-languageclient';
1923
import { LanguageClient } from 'vscode-languageclient/node';
2024
import {
2125
AddParameterCommandArgs,
2226
alsAddParameterCommandExecutor,
2327
} from './refactoring/alsAddParameterCommand';
2428

25-
type CommandExecuter = (
29+
/**
30+
* Type alias for a function that intercepts a command and executes it by return a promise that
31+
* resolve to an ExecuteCommandSignature if the command was executed successfully or undefined
32+
* otherwise.
33+
*/
34+
type CommandExecutor = (
2635
command: string,
2736
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2837
args: any[],
2938
next: ExecuteCommandSignature
3039
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3140
) => Promise<ExecuteCommandSignature | undefined>;
3241

33-
export const alsCommandExecuter = (client: LanguageClient): CommandExecuter => {
42+
/**
43+
* Returns a CommandExecutor that will use client to intercept and execute commands
44+
*
45+
* @param client - An ALS LanguageClient
46+
* @returns A CommandExecutor that dispatches command to a specific executor
47+
*/
48+
export const alsCommandExecutor = (client: LanguageClient): CommandExecutor => {
3449
return async (
3550
command: string,
3651
// eslint-disable-next-line @typescript-eslint/no-explicit-any

integration/vscode/ada/src/alsProtocolExtensions.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,75 @@
1515
-- of the license. --
1616
----------------------------------------------------------------------------*/
1717

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+
1823
import { LanguageClient } from 'vscode-languageclient/node';
1924

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+
*/
2032
export enum AdaGrammarRule {
2133
Defining_Id_Rule = 'Defining_Id_Rule',
2234
Defining_Id_List_Rule = 'Defining_Id_List_Rule',
2335
Param_Spec_Rule = 'Param_Spec_Rule',
2436
}
2537

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+
*/
2644
type AdaSyntaxCheckRequest = {
2745
input: string;
2846
rules: string[];
2947
};
3048

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+
*/
3155
type AdaSyntaxCheckResponse = {
3256
diagnostic?: string;
3357
};
3458

59+
/**
60+
* Class that implements an a syntax check request as an extension to the LSP
61+
*/
3562
export class AdaSyntaxCheckProvider {
3663
private readonly client: LanguageClient;
3764
rules: string[];
3865
diagnostic?: string;
3966

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+
*/
4074
constructor(client: LanguageClient, rules: AdaGrammarRule[], diagnotic?: string) {
4175
this.client = client;
4276
this.rules = rules.map((rule) => rule.toString());
4377
this.diagnostic = diagnotic;
4478
}
4579

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+
*/
4687
public sendCheckSyntaxRequest = async (input: string): Promise<undefined | string> => {
4788
const method = '$/alsCheckSyntax';
4889

integration/vscode/ada/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import * as process from 'process';
2727

2828
import GPRTaskProvider from './gprTaskProvider';
2929
import gnatproveTaskProvider from './gnatproveTaskProvider';
30-
import { alsCommandExecuter } from './alsExecuteCommand';
30+
import { alsCommandExecutor } from './alsExecuteCommand';
3131

3232
let alsTaskProvider: vscode.Disposable[] = [
3333
vscode.tasks.registerTaskProvider(GPRTaskProvider.gprBuildType, new GPRTaskProvider()),
@@ -63,7 +63,7 @@ export function activate(context: vscode.ExtensionContext): void {
6363
// Create the language client and start the client.
6464
const client = new LanguageClient('ada', 'Ada Language Server', serverOptions, clientOptions);
6565
const alsMiddleware: Middleware = {
66-
executeCommand: alsCommandExecuter(client),
66+
executeCommand: alsCommandExecutor(client),
6767
};
6868
client.clientOptions.middleware = alsMiddleware;
6969

integration/vscode/ada/src/refactoring/alsAddParameterCommand.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,44 @@
1515
-- of the license. --
1616
----------------------------------------------------------------------------*/
1717

18+
/**
19+
* This file contains all the constructs necessary to execute the 'als-refactor-add-parameters'
20+
* command
21+
*/
22+
1823
import { window, InputBoxOptions } from 'vscode';
1924
import { LanguageClient } from 'vscode-languageclient/node';
2025

2126
import { AdaGrammarRule, AdaSyntaxCheckProvider } from '../alsProtocolExtensions';
2227

28+
/* ALS will send a 'als-refactor-add-parameters' command with at least two arguments:
29+
* 'newParameter' and 'requiresFullSpecification'.
30+
* 'newParameter' will be filled by alsAddParameterCommandExecutor and
31+
* 'requiresFullSpecification' is used to determined the syntax rules used to check if the input
32+
* is valid.
33+
*/
2334
export type AddParameterCommandArgs = {
2435
newParameter: string;
2536
requiresFullSpecification: boolean;
2637
};
2738

39+
/**
40+
* Executes the 'als-refactor-add-parameters' command by manipulating args.newParameter with
41+
* the user input. The user input is also syntactically checked, by sending a '$/alsCheckSyntax'
42+
* request to ALS. This request requires a set of rules, which depend on
43+
* args.requiresFullSpecification
44+
*
45+
* @param client - The language server client needed to interact with ALS
46+
* @param args - Arguments of the 'als-refactor-add-parameters' command
47+
* @returns A Promise<boolean> that resolves to true if the command was executed successfully and
48+
* false otherwise
49+
*/
2850
export const alsAddParameterCommandExecutor = async (
2951
client: LanguageClient,
3052
args: AddParameterCommandArgs
3153
): Promise<boolean> => {
3254
// If the server command attributes changed, some of args fields might be undefined
55+
3356
if (args.requiresFullSpecification === undefined || args.newParameter === undefined) {
3457
return Promise.reject(
3558
'Invalid als-refactor-add-parameters command: missing "requiresFullSpecification" field'

0 commit comments

Comments
 (0)