Skip to content

Commit c725e18

Browse files
committed
Unittest Language Server spawning
Fixes #422
1 parent b0c8bdb commit c725e18

File tree

8 files changed

+127
-2
lines changed

8 files changed

+127
-2
lines changed

.vscode/launch.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"request": "launch",
1919
"runtimeExecutable": "${execPath}",
2020
"args": [
21+
"${workspaceFolder}/test/resources",
22+
"--install-extension",
23+
"ms-vscode.cpptools",
24+
"--disable-extensions",
2125
"--extensionDevelopmentPath=${workspaceFolder}",
2226
"--extensionTestsPath=${workspaceFolder}/out/test"
2327
],

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"fortran.formatting.findentArgs": ["-Cn", "--align-paren=1"],
5858
// Fortran-Language-Server specific options
5959
"fortran.fortls.incrementalSync": true,
60-
"fortran.fortls.preserveKeywordOrder": true,
6160
// Other Fortran options
6261
"fortran.preferredCase": "lowercase"
6362
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Added
1313

14+
- Added unittest for `fortls` spawning and integration, checks for initialization values
15+
([#422](https://github.com/fortran-lang/vscode-fortran-support/issues/422))
1416
- Added warning notifications for extensions that interfere with Modern Fortran
1517
([#458](https://github.com/fortran-lang/vscode-fortran-support/issues/458))
1618
- Added single file and multiple workspace folder support for the Language Server

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export async function activate(context: vscode.ExtensionContext) {
8787
},
8888
})
8989
);
90+
return context;
9091
}
9192

9293
function detectDeprecatedOptions() {

test/lsp-client.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as vscode from 'vscode';
2+
import * as path from 'path';
3+
import { strictEqual } from 'assert';
4+
import { spawnSync } from 'child_process';
5+
import { LoggingService } from '../src/services/logging-service';
6+
import { FortlsClient } from '../src/lsp/client';
7+
8+
suite('Language Server integration tests', () => {
9+
let doc: vscode.TextDocument;
10+
const server = new FortlsClient(new LoggingService());
11+
const fileUri = vscode.Uri.file(
12+
path.resolve(__dirname, '../../test/resources/function_subroutine_definitions.f90')
13+
);
14+
15+
suiteSetup(async function (): Promise<void> {
16+
console.log('Installing fortls Language Server');
17+
spawnSync('pip', ['install', '--user', '--upgrade', 'fortls']);
18+
});
19+
20+
test('Launch fortls & Check Initialization Response', async () => {
21+
await server.activate();
22+
doc = await vscode.workspace.openTextDocument(fileUri);
23+
await vscode.window.showTextDocument(doc);
24+
25+
const ref = {
26+
capabilities: {
27+
completionProvider: {
28+
resolveProvider: false,
29+
triggerCharacters: ['%'],
30+
},
31+
definitionProvider: true,
32+
documentSymbolProvider: true,
33+
referencesProvider: true,
34+
hoverProvider: true,
35+
implementationProvider: true,
36+
renameProvider: true,
37+
workspaceSymbolProvider: true,
38+
textDocumentSync: 2,
39+
signatureHelpProvider: {
40+
triggerCharacters: ['(', ','],
41+
},
42+
codeActionProvider: true,
43+
},
44+
};
45+
strictEqual(JSON.stringify(ref) === JSON.stringify(server['client'].initializeResult), true);
46+
});
47+
48+
suiteTeardown(async function (): Promise<void> {
49+
console.log('Deactivate fortls');
50+
await server.deactivate();
51+
});
52+
});

test/resources/.vscode/launch.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch current F90",
9+
"type": "cppdbg",
10+
"request": "launch",
11+
"program": "${fileDirname}/${fileBasenameNoExtension}",
12+
"cwd": "${fileDirname}",
13+
"stopAtEntry": false,
14+
"environment": [],
15+
"externalConsole": false,
16+
"MIMode": "gdb",
17+
"setupCommands": [
18+
{
19+
"description": "Enable pretty-printing for gdb",
20+
"text": "-enable-pretty-printing",
21+
"ignoreFailures": true
22+
},
23+
{
24+
"description": "Set Disassembly Flavor to Intel",
25+
"text": "-gdb-set disassembly-flavor intel",
26+
"ignoreFailures": true
27+
}
28+
],
29+
"preLaunchTask": "compile",
30+
"logging": {
31+
"engineLogging": false,
32+
"moduleLoad": true,
33+
"exceptions": true
34+
}
35+
}
36+
]
37+
}

test/resources/.vscode/tasks.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "compile",
8+
"type": "shell",
9+
"command": "gfortran",
10+
"args": ["-Wall", "-g", "${file}", "-o${fileDirname}/${fileBasenameNoExtension}"],
11+
"presentation": {
12+
"echo": true,
13+
"reveal": "always",
14+
"focus": false,
15+
"panel": "shared"
16+
},
17+
"group": {
18+
"kind": "build",
19+
"isDefault": true
20+
},
21+
"problemMatcher": "$gcc"
22+
}
23+
]
24+
}

test/runTest.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ async function main() {
77
// The folder containing the Extension Manifest package.json
88
// Passed to `--extensionDevelopmentPath`
99
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
10+
const workspacePath = path.resolve(__dirname, '../../test/resources/');
1011

1112
// The path to the extension test runner script
1213
// Passed to --extensionTestsPath
1314
const extensionTestsPath = path.resolve(__dirname, './index');
1415

15-
const launchArgs = ['--disable-extensions', '--install-extension', 'ms-vscode.cpptools'];
16+
const launchArgs = [
17+
workspacePath,
18+
'--disable-extensions',
19+
'--install-extension',
20+
'ms-vscode.cpptools',
21+
];
1622
// Download VS Code, unzip it and run the integration test
1723
await runTests({
1824
launchArgs,

0 commit comments

Comments
 (0)