Skip to content

Unittest Language Server spawning #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: CI
on: [push, pull_request]
jobs:
grammar:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
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
2 changes: 2 additions & 0 deletions src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const saveKeywordToJson = keyword => {
});
};

export const delay = (ms: number) => new Promise(res => setTimeout(res, ms));

export function isUri(input: any): input is vscode.Uri {
return input && input instanceof vscode.Uri;
}
Expand Down
50 changes: 50 additions & 0 deletions test/lsp-client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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';
import { delay } from '../src/lib/helper';

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']);
await server.activate();
});

test('Launch fortls & Check Initialization Response', async () => {
await delay(3000); // wait for server to initialize
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,
},
};
const res = server['client'].initializeResult;
strictEqual(JSON.stringify(ref), JSON.stringify(res));
});
});
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