Skip to content

Commit 589bb81

Browse files
authored
Merge pull request #302 from krvajal/update
Update
2 parents 4ed05e2 + a15cc14 commit 589bb81

File tree

11 files changed

+105
-2128
lines changed

11 files changed

+105
-2128
lines changed

.github/workflows/main.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ jobs:
1313
with:
1414
node-version: ${{ matrix.node-version }}
1515
- name: Installing Extension
16-
run: yarn install
16+
run: npm ci
1717
- name: Compile
18-
run: yarn compile
18+
run: npm run compile
1919
- name: Linting
20-
run: yarn lint
20+
run: npm run lint
2121
- name: Test Syntax Highlighting
22-
run: yarn test:grammar
22+
run: npm run test:grammar
2323
- name: Test Unittests
2424
uses: GabrielBB/xvfb-action@v1
2525
with:
26-
run: yarn test
26+
run: npm test

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ First of all, this is a Visual Studio Code extension that uses TypeScript and to
1111
1. Fork the repo
1212
2. Clone your fork
1313
3. Create a branch
14-
4. Run `yarn install`
15-
5. To test the extension run `yarn test:grammar && yarn test`
14+
4. Run `npm install`
15+
5. To test the extension run `npm run test:grammar && npm test`

src/extension.ts

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import FortranHoverProvider from './features/hover-provider';
77
import { FortranCompletionProvider } from './features/completion-provider';
88
import { FortranDocumentSymbolProvider } from './features/document-symbol-provider';
99

10-
import { FortranLangServer } from './lang-server';
11-
import { FORTRAN_DOCUMENT_SELECTOR, EXTENSION_ID, promptForMissingTool } from './lib/helper';
1210
import { LoggingService } from './services/logging-service';
1311
import * as pkg from '../package.json';
1412
import { LANG_SERVER_TOOL_ID } from './lib/tools';
1513
import { FortranFormattingProvider } from './features/formatting-provider';
14+
import { EXTENSION_ID, FortranDocumentSelector, promptForMissingTool } from './lib/tools';
1615

1716
// Make it global to catch errors when activation fails
1817
const loggingService = new LoggingService();
@@ -26,15 +25,15 @@ export function activate(context: vscode.ExtensionContext) {
2625
if (extensionConfig.get('linterEnabled', true)) {
2726
const linter = new FortranLintingProvider(loggingService);
2827
linter.activate(context.subscriptions);
29-
vscode.languages.registerCodeActionsProvider(FORTRAN_DOCUMENT_SELECTOR, linter);
28+
vscode.languages.registerCodeActionsProvider(FortranDocumentSelector(), linter);
3029
loggingService.logInfo('Linter is enabled');
3130
} else {
3231
loggingService.logInfo('Linter is not enabled');
3332
}
3433

3534
if (extensionConfig.get('formatter') !== 'Disabled') {
3635
const disposable: vscode.Disposable = vscode.languages.registerDocumentFormattingEditProvider(
37-
FORTRAN_DOCUMENT_SELECTOR,
36+
FortranDocumentSelector(),
3837
new FortranFormattingProvider(loggingService)
3938
);
4039
context.subscriptions.push(disposable);
@@ -45,22 +44,22 @@ export function activate(context: vscode.ExtensionContext) {
4544

4645
if (extensionConfig.get('provideCompletion', true)) {
4746
const completionProvider = new FortranCompletionProvider(loggingService);
48-
vscode.languages.registerCompletionItemProvider(FORTRAN_DOCUMENT_SELECTOR, completionProvider);
47+
vscode.languages.registerCompletionItemProvider(FortranDocumentSelector(), completionProvider);
4948
} else {
5049
loggingService.logInfo('Completion Provider is not enabled');
5150
}
5251

5352
if (extensionConfig.get('provideHover', true)) {
5453
const hoverProvider = new FortranHoverProvider(loggingService);
55-
vscode.languages.registerHoverProvider(FORTRAN_DOCUMENT_SELECTOR, hoverProvider);
54+
vscode.languages.registerHoverProvider(FortranDocumentSelector(), hoverProvider);
5655
loggingService.logInfo('Hover Provider is enabled');
5756
} else {
5857
loggingService.logInfo('Hover Provider is not enabled');
5958
}
6059

6160
if (extensionConfig.get('provideSymbols', true)) {
6261
const symbolProvider = new FortranDocumentSymbolProvider();
63-
vscode.languages.registerDocumentSymbolProvider(FORTRAN_DOCUMENT_SELECTOR, symbolProvider);
62+
vscode.languages.registerDocumentSymbolProvider(FortranDocumentSelector(), symbolProvider);
6463
loggingService.logInfo('Symbol Provider is enabled');
6564
} else {
6665
loggingService.logInfo('Symbol Provider is not enabled');
@@ -74,30 +73,4 @@ export function activate(context: vscode.ExtensionContext) {
7473
https://github.com/hansec/fortran-language-server`;
7574
promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService);
7675
}
77-
78-
// Check that Fortran Intellisense is installed and if not prompt to install
79-
if (!vscode.extensions.getExtension('hansec.fortran-ls')) {
80-
const msg = `It is highly recommended to install the Fortran IntelliSense
81-
extension. The extension is used to interface with the
82-
fortran-language-server.
83-
For a full list of features provided by the extension see:
84-
https://github.com/hansec/vscode-fortran-ls`;
85-
promptForMissingTool('hansec.fortran-ls', msg, 'VSExt', loggingService);
86-
}
87-
88-
// Our interface with `fortls` has been disabled in favour of the @hansec's
89-
// VS Code extension Fortran IntelliSense
90-
const useInternalFLInterface = false;
91-
if (useInternalFLInterface) {
92-
const langServer = new FortranLangServer(context, extensionConfig);
93-
langServer.start();
94-
langServer.onReady().then(() => {
95-
const capabilities = langServer.getCapabilities();
96-
if (!capabilities) {
97-
return vscode.window.showErrorMessage(
98-
'The language server is not able to serve any features at the moment.'
99-
);
100-
}
101-
});
102-
}
10376
}

src/features/completion-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as vscode from 'vscode';
44
import { isPositionInString, intrinsics, FORTRAN_KEYWORDS } from '../lib/helper';
55
import { getDeclaredFunctions } from '../lib/functions';
66

7-
import { EXTENSION_ID } from '../lib/helper';
7+
import { EXTENSION_ID } from '../lib/tools';
88
import { LoggingService } from '../services/logging-service';
99

1010
class CaseCoverter {

src/features/formatting-provider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import * as which from 'which';
66
import * as vscode from 'vscode';
77
import * as cp from 'child_process';
88

9-
import { FORMATTERS } from '../lib/tools';
109
import { LoggingService } from '../services/logging-service';
11-
import { EXTENSION_ID, promptForMissingTool } from '../lib/helper';
10+
import { FORMATTERS, EXTENSION_ID, promptForMissingTool } from '../lib/tools';
1211

1312
export class FortranFormattingProvider implements vscode.DocumentFormattingEditProvider {
1413
constructor(private logger: LoggingService) {}

src/features/linter-provider.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
import * as path from 'path';
44
import * as cp from 'child_process';
5-
import { FORTRAN_DOCUMENT_SELECTOR, getIncludeParams } from '../lib/helper';
65

76
import * as vscode from 'vscode';
87
import { LoggingService } from '../services/logging-service';
9-
import { resolveVariables } from '../lib/tools';
8+
import { FortranDocumentSelector, resolveVariables } from '../lib/tools';
109
import * as fg from 'fast-glob';
1110
import { glob } from 'glob';
1211

@@ -21,8 +20,8 @@ export default class FortranLintingProvider {
2120

2221
// Only lint Fortran (free, fixed) format files
2322
if (
24-
!FORTRAN_DOCUMENT_SELECTOR.some(e => e.scheme === textDocument.uri.scheme) ||
25-
!FORTRAN_DOCUMENT_SELECTOR.some(e => e.language === textDocument.languageId)
23+
!FortranDocumentSelector().some(e => e.scheme === textDocument.uri.scheme) ||
24+
!FortranDocumentSelector().some(e => e.language === textDocument.languageId)
2625
) {
2726
return;
2827
}
@@ -111,7 +110,7 @@ export default class FortranLintingProvider {
111110
const fileNameWithoutExtension = textDocument.fileName.substring(0, extensionIndex);
112111
const argList = [
113112
...args,
114-
...getIncludeParams(includePaths), // include paths
113+
...this.getIncludeParams(includePaths), // include paths
115114
textDocument.fileName,
116115
`-o ${fileNameWithoutExtension}.mod`,
117116
];
@@ -222,4 +221,8 @@ export default class FortranLintingProvider {
222221
this.loggingService.logInfo(`Linter.arguments:\n${args.join('\r\n')}`);
223222
return args.map(e => resolveVariables(e));
224223
}
224+
225+
private getIncludeParams = (paths: string[]) => {
226+
return paths.map(path => `-I${path}`);
227+
};
225228
}

src/lang-server.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/lib/helper.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ import { installPythonTool } from './tools';
44
import intrinsics from './fortran-intrinsics';
55
import { LoggingService } from '../services/logging-service';
66

7-
// IMPORTANT: this should match the value
8-
// on the package.json otherwise the extension won't
9-
// work at all
10-
export const FORTRAN_DOCUMENT_SELECTOR = [
11-
{ scheme: 'file', language: 'FortranFreeForm' },
12-
{ scheme: 'file', language: 'FortranFixedForm' },
13-
];
147
export { intrinsics };
15-
export const EXTENSION_ID = 'fortran';
168

179
export const FORTRAN_KEYWORDS = [
1810
'FUNCTION',
@@ -84,10 +76,6 @@ export const _loadDocString = (keyword: string) => {
8476
return docText;
8577
};
8678

87-
export const getIncludeParams = (paths: string[]) => {
88-
return paths.map(path => `-I${path}`);
89-
};
90-
9179
export function isPositionInString(
9280
document: vscode.TextDocument,
9381
position: vscode.Position
@@ -112,52 +100,6 @@ const saveKeywordToJson = keyword => {
112100
});
113101
};
114102

115-
/**
116-
* Install a package either a Python pip package or a VS Marketplace Extension.
117-
*
118-
* For the Python install supply the name of the package in PyPi
119-
* e.g. fortran-language-server
120-
*
121-
* For the VS Extension to be installed supply the id of the extension
122-
* e.g 'hansec.fortran-ls'
123-
*
124-
* @param tool name of the tool e.g. fortran-language-server
125-
* @param msg optional message for installing said package
126-
* @param toolType type of tool, supports `Python` (through pip) and 'VSExt'
127-
*/
128-
export function promptForMissingTool(
129-
tool: string,
130-
msg: string,
131-
toolType: string,
132-
logger?: LoggingService
133-
) {
134-
const items = ['Install'];
135-
return new Promise((resolve, reject) => {
136-
resolve(
137-
vscode.window.showInformationMessage(msg, ...items).then(selected => {
138-
if (selected === 'Install') {
139-
switch (toolType) {
140-
case 'Python':
141-
installPythonTool(tool, logger);
142-
break;
143-
144-
case 'VSExt':
145-
logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`);
146-
vscode.commands.executeCommand('extension.open', tool);
147-
vscode.commands.executeCommand('workbench.extensions.installExtension', tool);
148-
logger.logInfo(`Extension ${tool} successfully installed`);
149-
break;
150-
151-
default:
152-
logger.logError(`Failed to install tool: ${tool}`);
153-
break;
154-
}
155-
}
156-
})
157-
);
158-
});
159-
}
160-
161103
export function isUri(input: any): input is vscode.Uri {
162104
return input && input instanceof vscode.Uri;
163105
}

src/lib/linter.ts

Whitespace-only changes.

src/lib/tools.ts

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,95 @@
1-
export const LANG_SERVER_TOOL_ID = 'fortran-language-server';
2-
export const FORMATTERS = ['Disabled', 'findent', 'fprettify'];
3-
41
import * as os from 'os';
52
import * as vscode from 'vscode';
63
import * as assert from 'assert';
74
import * as cp from 'child_process';
85
import { LoggingService } from '../services/logging-service';
96
import { isString, isArrayOfString } from './helper';
107

8+
export const EXTENSION_ID = 'fortran';
9+
export const LANG_SERVER_TOOL_ID = 'fortran-language-server';
10+
export const FORMATTERS = ['Disabled', 'findent', 'fprettify'];
11+
1112
// Platform-specific environment variable delimiter
1213
export const envDelimiter: string = process.platform === 'win32' ? ';' : ':';
1314

15+
/**
16+
* Generates a document selector for the supported file and languages
17+
* if the folder is present then a glob pattern for all the files in the workspace
18+
* is included
19+
*
20+
* @warning this should match the value on the package.json otherwise the extension
21+
* won't work at all
22+
*
23+
* @param folder `optional` WorkspaceFolder to search
24+
* @returns tuple of DocumentSelector
25+
*/
26+
export function FortranDocumentSelector(folder?: vscode.WorkspaceFolder) {
27+
if (folder) {
28+
return [
29+
{ scheme: 'file', language: 'FortranFreeForm', pattern: `${folder.uri.fsPath}/**/*` },
30+
{ scheme: 'file', language: 'FortranFixedForm', pattern: `${folder.uri.fsPath}/**/*` },
31+
];
32+
} else {
33+
return [
34+
{ scheme: 'file', language: 'FortranFreeForm' },
35+
{ scheme: 'file', language: 'FortranFixedForm' },
36+
];
37+
}
38+
}
39+
40+
/**
41+
* Install a package either a Python pip package or a VS Marketplace Extension.
42+
*
43+
* For the Python install supply the name of the package in PyPi
44+
* e.g. fortran-language-server
45+
*
46+
* For the VS Extension to be installed supply the id of the extension
47+
* e.g 'hansec.fortran-ls'
48+
*
49+
* @param tool name of the tool e.g. fortran-language-server
50+
* @param msg optional message for installing said package
51+
* @param toolType type of tool, supports `Python` (through pip) and 'VSExt'
52+
*/
53+
export function promptForMissingTool(
54+
tool: string,
55+
msg: string,
56+
toolType: string,
57+
logger?: LoggingService
58+
) {
59+
const items = ['Install'];
60+
return new Promise((resolve, reject) => {
61+
resolve(
62+
vscode.window.showInformationMessage(msg, ...items).then(selected => {
63+
if (selected === 'Install') {
64+
switch (toolType) {
65+
case 'Python':
66+
installPythonTool(tool, logger);
67+
break;
68+
69+
case 'VSExt':
70+
logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`);
71+
vscode.commands.executeCommand('extension.open', tool);
72+
vscode.commands.executeCommand('workbench.extensions.installExtension', tool);
73+
logger.logInfo(`Extension ${tool} successfully installed`);
74+
break;
75+
76+
default:
77+
logger.logError(`Failed to install tool: ${tool}`);
78+
break;
79+
}
80+
}
81+
})
82+
);
83+
});
84+
}
85+
86+
/**
87+
* A wrapper around a call to `pip` for installing external tools.
88+
* Does not explicitly check if `pip` is installed.
89+
*
90+
* @param pyPackage name of python package in PyPi
91+
* @param logger `optional` logging channel for output
92+
*/
1493
export function installPythonTool(pyPackage: string, logger?: LoggingService) {
1594
const installProcess = cp.spawn('pip', 'install --user --upgrade '.concat(pyPackage).split(' '));
1695
installProcess.stdout.on('data', data => {

0 commit comments

Comments
 (0)