Skip to content

Commit 32be366

Browse files
committed
test: added native symbol provider test
1 parent 01a1f7b commit 32be366

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

src/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ export async function activate(context: vscode.ExtensionContext) {
114114
await showWhatsNew();
115115
fs.writeFileSync(path.join(__dirname, 'displayReleaseNotes.txt'), 'false');
116116
}
117+
// const GoToHelp = 'Go to Help';
118+
// vscode.window.showInformationMessage('Click for more Info', GoToHelp).then(selection => {
119+
// if (selection === GoToHelp) {
120+
// vscode.env.openExternal(
121+
// vscode.Uri.parse(
122+
// 'https://github.com/fortran-lang/vscode-fortran-support/blob/main/updates/RELEASE_NOTES-v3.2.md'
123+
// )
124+
// );
125+
// }
126+
// });
117127
return context;
118128
}
119129

src/features/document-symbol-provider.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* c8 ignore start */
21
import { CancellationToken, TextDocument, TextLine, SymbolInformation } from 'vscode';
32

43
import * as vscode from 'vscode';
@@ -29,9 +28,9 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
2928
return Promise.race([this.parseDoc(document), cancel]);
3029
}
3130

32-
parseDoc = async (document: TextDocument) => {
31+
private async parseDoc(document: TextDocument) {
3332
const lines = document.lineCount;
34-
let symbols = [];
33+
let symbols: SymbolInformation[] = [];
3534
const symbolTypes = this.getSymbolTypes();
3635

3736
for (let i = 0; i < lines; i++) {
@@ -48,9 +47,9 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
4847
}
4948
}
5049
return symbols;
51-
};
50+
}
5251

53-
getSymbolsOfType(type: 'subroutine' | 'function' | 'variable'): ParserFunc {
52+
private getSymbolsOfType(type: 'subroutine' | 'function' | 'variable'): ParserFunc {
5453
switch (type) {
5554
case 'subroutine':
5655
return this.parseSubroutineDefinition;
@@ -93,6 +92,7 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
9392
}
9493
}
9594

95+
/* c8 ignore start */
9696
private parseVariableDefinition(document: TextDocument, line: TextLine) {
9797
const variable = getDeclaredVar(line);
9898
if (variable) {
@@ -105,12 +105,10 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
105105
);
106106
}
107107
}
108+
/* c8 ignore stop */
108109

109-
getSymbolTypes() {
110-
const config = vscode.workspace.getConfiguration(EXTENSION_ID);
111-
// It does not make much sense for this to be an input option
110+
private getSymbolTypes() {
112111
const symbolTypes: SymbolType[] = ['subroutine', 'function'];
113112
return symbolTypes;
114113
}
115114
}
116-
/* c8 ignore stop */

test/fortran/sample.f90

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
program main
2-
2+
integer :: var
3+
var = foo(1)
34
call say_hello(1, 2)
5+
! comment
6+
#define PREPROC
47

58
contains
69

@@ -10,4 +13,10 @@ subroutine say_hello(a,b)
1013
print *, "Hello, World!"
1114
end subroutine say_hello
1215

16+
function foo(val) result(res)
17+
integer, intent(in) :: val
18+
integer :: res
19+
res = val + 1
20+
end function foo
21+
1322
end program main
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as path from 'path';
2+
import * as vscode from 'vscode';
3+
import { strictEqual } from 'assert';
4+
import { FortranDocumentSymbolProvider } from '../../src/features/document-symbol-provider';
5+
6+
suite('Document Symbol Provider', () => {
7+
let doc: vscode.TextDocument;
8+
const fileUri = vscode.Uri.file(path.resolve(__dirname, '../../../test/fortran/sample.f90'));
9+
10+
suiteSetup(async () => {
11+
doc = await vscode.workspace.openTextDocument(fileUri);
12+
await vscode.window.showTextDocument(doc);
13+
});
14+
15+
test('should return symbols', async () => {
16+
const provider = new FortranDocumentSymbolProvider();
17+
const symbols = await provider.provideDocumentSymbols(
18+
doc,
19+
new vscode.CancellationTokenSource().token
20+
);
21+
strictEqual(symbols.length, 2);
22+
});
23+
});

0 commit comments

Comments
 (0)