Skip to content

Commit 69e81d8

Browse files
authored
Merge pull request #463 from fortran-lang/gnikit/issue422
Unittest Language Server spawning
2 parents b0c8bdb + 812fb43 commit 69e81d8

File tree

10 files changed

+129
-3
lines changed

10 files changed

+129
-3
lines changed

.github/workflows/main.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: CI
22
on: [push, pull_request]
33
jobs:
4-
grammar:
4+
tests:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
88
node-version: [14.x, 16.x]
9+
fail-fast: false
910
steps:
1011
- uses: actions/checkout@v3
1112
- name: Use Node.js ${{ matrix.node-version }}

.vscode/launch.json

+4
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

-1
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

+2
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

+1
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() {

src/lib/helper.ts

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const saveKeywordToJson = keyword => {
7878
});
7979
};
8080

81+
export const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
82+
8183
export function isUri(input: any): input is vscode.Uri {
8284
return input && input instanceof vscode.Uri;
8385
}

test/lsp-client.test.ts

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

test/resources/.vscode/launch.json

+37
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

+24
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

+7-1
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)