From c725e18a9e0778e095d558292d909520b65aa058 Mon Sep 17 00:00:00 2001 From: gnikit Date: Fri, 6 May 2022 21:50:13 +0100 Subject: [PATCH] Unittest Language Server spawning Fixes #422 --- .vscode/launch.json | 4 +++ .vscode/settings.json | 1 - CHANGELOG.md | 2 ++ src/extension.ts | 1 + test/lsp-client.test.ts | 52 ++++++++++++++++++++++++++++++ test/resources/.vscode/launch.json | 37 +++++++++++++++++++++ test/resources/.vscode/tasks.json | 24 ++++++++++++++ test/runTest.ts | 8 ++++- 8 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 test/lsp-client.test.ts create mode 100644 test/resources/.vscode/launch.json create mode 100644 test/resources/.vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 512959c0..893d5335 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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" ], diff --git a/.vscode/settings.json b/.vscode/settings.json index e576c636..96d37d9c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 58719cf8..4953562c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/extension.ts b/src/extension.ts index 6b94e44d..5b75efbd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -87,6 +87,7 @@ export async function activate(context: vscode.ExtensionContext) { }, }) ); + return context; } function detectDeprecatedOptions() { diff --git a/test/lsp-client.test.ts b/test/lsp-client.test.ts new file mode 100644 index 00000000..d00df189 --- /dev/null +++ b/test/lsp-client.test.ts @@ -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 { + 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 { + console.log('Deactivate fortls'); + await server.deactivate(); + }); +}); diff --git a/test/resources/.vscode/launch.json b/test/resources/.vscode/launch.json new file mode 100644 index 00000000..845ccd93 --- /dev/null +++ b/test/resources/.vscode/launch.json @@ -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 + } + } + ] +} diff --git a/test/resources/.vscode/tasks.json b/test/resources/.vscode/tasks.json new file mode 100644 index 00000000..bc83c37a --- /dev/null +++ b/test/resources/.vscode/tasks.json @@ -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" + } + ] +} diff --git a/test/runTest.ts b/test/runTest.ts index 0d34d797..8556f82f 100644 --- a/test/runTest.ts +++ b/test/runTest.ts @@ -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,