Skip to content

Commit

Permalink
Unittest Language Server spawning
Browse files Browse the repository at this point in the history
Fixes #422
  • Loading branch information
gnikit committed May 6, 2022
1 parent b0c8bdb commit c725e18
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceFolder}/test/resources",
"--install-extension",
"ms-vscode.cpptools",
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"fortran.formatting.findentArgs": ["-Cn", "--align-paren=1"],
// Fortran-Language-Server specific options
"fortran.fortls.incrementalSync": true,
"fortran.fortls.preserveKeywordOrder": true,
// Other Fortran options
"fortran.preferredCase": "lowercase"
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Added unittest for `fortls` spawning and integration, checks for initialization values
([#422](https://github.com/fortran-lang/vscode-fortran-support/issues/422))
- Added warning notifications for extensions that interfere with Modern Fortran
([#458](https://github.com/fortran-lang/vscode-fortran-support/issues/458))
- Added single file and multiple workspace folder support for the Language Server
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export async function activate(context: vscode.ExtensionContext) {
},
})
);
return context;
}

function detectDeprecatedOptions() {
Expand Down
52 changes: 52 additions & 0 deletions test/lsp-client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { strictEqual } from 'assert';
import { spawnSync } from 'child_process';
import { LoggingService } from '../src/services/logging-service';
import { FortlsClient } from '../src/lsp/client';

suite('Language Server integration tests', () => {
let doc: vscode.TextDocument;
const server = new FortlsClient(new LoggingService());
const fileUri = vscode.Uri.file(
path.resolve(__dirname, '../../test/resources/function_subroutine_definitions.f90')
);

suiteSetup(async function (): Promise<void> {
console.log('Installing fortls Language Server');
spawnSync('pip', ['install', '--user', '--upgrade', 'fortls']);
});

test('Launch fortls & Check Initialization Response', async () => {
await server.activate();
doc = await vscode.workspace.openTextDocument(fileUri);
await vscode.window.showTextDocument(doc);

const ref = {
capabilities: {
completionProvider: {
resolveProvider: false,
triggerCharacters: ['%'],
},
definitionProvider: true,
documentSymbolProvider: true,
referencesProvider: true,
hoverProvider: true,
implementationProvider: true,
renameProvider: true,
workspaceSymbolProvider: true,
textDocumentSync: 2,
signatureHelpProvider: {
triggerCharacters: ['(', ','],
},
codeActionProvider: true,
},
};
strictEqual(JSON.stringify(ref) === JSON.stringify(server['client'].initializeResult), true);
});

suiteTeardown(async function (): Promise<void> {
console.log('Deactivate fortls');
await server.deactivate();
});
});
37 changes: 37 additions & 0 deletions test/resources/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch current F90",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"cwd": "${fileDirname}",
"stopAtEntry": false,
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "compile",
"logging": {
"engineLogging": false,
"moduleLoad": true,
"exceptions": true
}
}
]
}
24 changes: 24 additions & 0 deletions test/resources/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"command": "gfortran",
"args": ["-Wall", "-g", "${file}", "-o${fileDirname}/${fileBasenameNoExtension}"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc"
}
]
}
8 changes: 7 additions & 1 deletion test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ async function main() {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
const workspacePath = path.resolve(__dirname, '../../test/resources/');

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

const launchArgs = ['--disable-extensions', '--install-extension', 'ms-vscode.cpptools'];
const launchArgs = [
workspacePath,
'--disable-extensions',
'--install-extension',
'ms-vscode.cpptools',
];
// Download VS Code, unzip it and run the integration test
await runTests({
launchArgs,
Expand Down

0 comments on commit c725e18

Please sign in to comment.