Skip to content

Commit 92c6884

Browse files
authored
Merge pull request #274 from krvajal/updates
Updates
2 parents 7e3fe99 + 2e20efa commit 92c6884

File tree

11 files changed

+1934
-2036
lines changed

11 files changed

+1934
-2036
lines changed

.github/workflows/main.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
node-version: ${{ matrix.node-version }}
1515
- name: Installing Extension
1616
run: yarn install
17+
- name: Compile
18+
run: yarn compile
1719
- name: Test Syntax Highlighting
1820
run: yarn test:grammar
1921
- name: Test Unittests

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [2.4.2]
11+
12+
### Fixed
13+
14+
- Extension now activates for `FortranFixedForm`
15+
([#257](https://github.com/krvajal/vscode-fortran-support/issues/257))
16+
- Linting is now operational for `FortranFixedForm`
17+
([#258](https://github.com/krvajal/vscode-fortran-support/issues/258))
18+
19+
### Changed
20+
21+
- Renamed the Fixed Format Format language from `fortran_fixed-form` to
22+
`FortranFixedForm`, an alias has been added for backwards compatibility
23+
([#259](https://github.com/krvajal/vscode-fortran-support/issues/259))
24+
25+
### Removed
26+
27+
- Removes `paths.js` for detecting binaries in favour of `which`
28+
29+
## [2.4.1]
30+
1031
### Fixed
1132

1233
- Fixes dummy variable list erroneous syntax highlighting
@@ -278,7 +299,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
278299

279300
- Initial release
280301

281-
[unreleased]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.0...HEAD
302+
[unreleased]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.2...HEAD
303+
[2.4.2]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.1...v2.4.2
304+
[2.4.1]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.0...v2.4.1
282305
[2.4.0]: https://github.com/krvajal/vscode-fortran-support/compare/v2.3.0...v2.4.0
283306
[2.3.0]: https://github.com/krvajal/vscode-fortran-support/compare/v2.2.2...v2.3.0
284307
[2.2.2]: https://github.com/krvajal/vscode-fortran-support/compare/2.2.1...v2.2.1

package-lock.json

Lines changed: 1747 additions & 1888 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"engines": {
19-
"vscode": "^1.30.x"
19+
"vscode": "^1.52.x"
2020
},
2121
"icon": "images/icon.png",
2222
"homepage": "https://github.com/krvajalmiguelangel/vscode-fortran-support",
@@ -39,7 +39,8 @@
3939
"Debuggers"
4040
],
4141
"activationEvents": [
42-
"onLanguage:FortranFreeForm"
42+
"onLanguage:FortranFreeForm",
43+
"onLanguage:FortranFixedForm"
4344
],
4445
"main": "./out/src/extension",
4546
"extensionDependencies": [
@@ -72,11 +73,12 @@
7273
"configuration": "./language-configuration.json"
7374
},
7475
{
75-
"id": "fortran_fixed-form",
76+
"id": "FortranFixedForm",
7677
"aliases": [
7778
"Fortran",
7879
"fortran",
79-
"FORTRAN77"
80+
"FORTRAN77",
81+
"fortran_fixed-form"
8082
],
8183
"extensions": [
8284
".f",
@@ -110,7 +112,7 @@
110112
]
111113
},
112114
{
113-
"language": "fortran_fixed-form",
115+
"language": "FortranFixedForm",
114116
"scopeName": "source.fortran.fixed",
115117
"path": "./syntaxes/fortran_fixed-form.tmLanguage.json"
116118
}
@@ -201,7 +203,7 @@
201203
"language": "FortranFreeForm"
202204
},
203205
{
204-
"language": "fortran_fixed-form"
206+
"language": "FortranFixedForm"
205207
}
206208
]
207209
},
@@ -245,6 +247,7 @@
245247
]
246248
},
247249
"dependencies": {
248-
"vscode-languageclient": "^7.0.0"
250+
"vscode-languageclient": "^7.0.0",
251+
"which": "^2.0.2"
249252
}
250253
}

src/extension.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
// src/extension.ts
2+
import * as which from 'which'
23
import * as vscode from 'vscode'
34

45
import FortranLintingProvider from './features/linter-provider'
56
import FortranHoverProvider from './features/hover-provider'
67
import { FortranCompletionProvider } from './features/completion-provider'
78
import { FortranDocumentSymbolProvider } from './features/document-symbol-provider'
89

9-
import { FORTRAN_FREE_FORM_ID, EXTENSION_ID } from './lib/helper'
10-
import { FortranLangServer, checkForLangServer } from './lang-server'
10+
import { FortranLangServer } from './lang-server'
11+
import { FORTRAN_DOCUMENT_SELECTOR, EXTENSION_ID, promptForMissingTool } from './lib/helper'
1112
import { LoggingService } from './services/logging-service'
1213
import * as pkg from '../package.json'
14+
import { LANG_SERVER_TOOL_ID } from './lib/tools'
1315

1416
export function activate(context: vscode.ExtensionContext) {
1517
const loggingService = new LoggingService()
@@ -21,15 +23,16 @@ export function activate(context: vscode.ExtensionContext) {
2123
if (extensionConfig.get('linterEnabled', true)) {
2224
let linter = new FortranLintingProvider(loggingService)
2325
linter.activate(context.subscriptions)
24-
vscode.languages.registerCodeActionsProvider(FORTRAN_FREE_FORM_ID, linter)
26+
vscode.languages.registerCodeActionsProvider(FORTRAN_DOCUMENT_SELECTOR, linter)
27+
loggingService.logInfo('Linter is enabled')
2528
} else {
2629
loggingService.logInfo('Linter is not enabled')
2730
}
2831

2932
if (extensionConfig.get('provideCompletion', true)) {
3033
let completionProvider = new FortranCompletionProvider(loggingService)
3134
vscode.languages.registerCompletionItemProvider(
32-
FORTRAN_FREE_FORM_ID,
35+
FORTRAN_DOCUMENT_SELECTOR,
3336
completionProvider
3437
)
3538
} else {
@@ -38,22 +41,46 @@ export function activate(context: vscode.ExtensionContext) {
3841

3942
if (extensionConfig.get('provideHover', true)) {
4043
let hoverProvider = new FortranHoverProvider(loggingService)
41-
vscode.languages.registerHoverProvider(FORTRAN_FREE_FORM_ID, hoverProvider)
44+
vscode.languages.registerHoverProvider(FORTRAN_DOCUMENT_SELECTOR, hoverProvider)
45+
loggingService.logInfo('Hover Provider is enabled')
4246
} else {
4347
loggingService.logInfo('Hover Provider is not enabled')
4448
}
4549

4650
if (extensionConfig.get('provideSymbols', true)) {
4751
let symbolProvider = new FortranDocumentSymbolProvider()
4852
vscode.languages.registerDocumentSymbolProvider(
49-
FORTRAN_FREE_FORM_ID,
53+
FORTRAN_DOCUMENT_SELECTOR,
5054
symbolProvider
5155
)
56+
loggingService.logInfo('Symbol Provider is enabled')
5257
} else {
5358
loggingService.logInfo('Symbol Provider is not enabled')
5459
}
5560

56-
if (checkForLangServer(extensionConfig)) {
61+
// Check if the language server is installed and if not prompt to install it
62+
if (!which.sync('fortls', { nothrow: true })) {
63+
let msg = `It is highly recommended to use the fortran-language-server to
64+
enable hover, peeking, gotos and many more.
65+
For a full list of features the language server adds see:
66+
https://github.com/hansec/fortran-language-server`;
67+
promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService);
68+
}
69+
70+
// Check that Fortran Intellisense is installed and if not prompt to install
71+
if (!vscode.extensions.getExtension('hansec.fortran-ls')) {
72+
let msg = `It is highly recommended to install the Fortran IntelliSense
73+
extension. The extension is used to interface with the
74+
fortran-language-server.
75+
For a full list of features provided by the extension see:
76+
https://github.com/hansec/vscode-fortran-ls`;
77+
promptForMissingTool('hansec.fortran-ls', msg, 'VSExt', loggingService);
78+
}
79+
80+
// Our interface with `fortls` has been disabled in favour of the @hansec's
81+
// VS Code extension Fortran IntelliSense
82+
const useInternalFLInterface = false;
83+
if (useInternalFLInterface) {
5784
const langServer = new FortranLangServer(context, extensionConfig)
5885
langServer.start()
5986
langServer.onReady().then(() => {

src/features/linter-provider.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22

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

77
import * as vscode from 'vscode'
88
import { LoggingService } from '../services/logging-service'
99

1010
export default class FortranLintingProvider {
11-
constructor(private loggingService: LoggingService) {}
11+
constructor(private loggingService: LoggingService) { }
1212

1313
private diagnosticCollection: vscode.DiagnosticCollection
1414

1515
private doModernFortranLint(textDocument: vscode.TextDocument) {
1616
const errorRegex: RegExp =
1717
/^([a-zA-Z]:\\)*([^:]*):([0-9]+):([0-9]+):\s+(.*)\s+.*?\s+(Error|Warning|Fatal Error):\s(.*)$/gm
1818

19+
// Only lint Fortran (free, fixed) format files
1920
if (
20-
textDocument.languageId !== LANGUAGE_ID ||
21-
textDocument.uri.scheme !== 'file'
21+
!FORTRAN_DOCUMENT_SELECTOR.some(e => e.scheme === textDocument.uri.scheme) ||
22+
!FORTRAN_DOCUMENT_SELECTOR.some(e => e.language === textDocument.languageId)
2223
) {
2324
return
2425
}
@@ -137,7 +138,7 @@ export default class FortranLintingProvider {
137138
private command: vscode.Disposable
138139

139140
public activate(subscriptions: vscode.Disposable[]) {
140-
this.diagnosticCollection = vscode.languages.createDiagnosticCollection()
141+
this.diagnosticCollection = vscode.languages.createDiagnosticCollection('Fortran')
141142

142143
vscode.workspace.onDidOpenTextDocument(
143144
this.doModernFortranLint,

src/lang-server.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import {
33
LanguageClientOptions,
44
Executable,
55
} from 'vscode-languageclient/node'
6+
import * as which from 'which'
67
import * as vscode from 'vscode'
78
import {
8-
getBinPath,
9-
FORTRAN_FREE_FORM_ID,
10-
promptForMissingTool,
9+
FORTRAN_DOCUMENT_SELECTOR,
1110
} from './lib/helper'
1211
import { LANG_SERVER_TOOL_ID } from './lib/tools'
1312

@@ -18,13 +17,13 @@ export class FortranLangServer {
1817
let langServerFlags: string[] = config.get('languageServerFlags', [])
1918

2019
const serverOptions: Executable = {
21-
command: getBinPath(LANG_SERVER_TOOL_ID),
20+
command: which.sync(LANG_SERVER_TOOL_ID),
2221
args: [...langServerFlags],
2322
options: {},
2423
}
2524

2625
const clientOptions: LanguageClientOptions = {
27-
documentSelector: [FORTRAN_FREE_FORM_ID],
26+
documentSelector: FORTRAN_DOCUMENT_SELECTOR,
2827
}
2928

3029
this.c = new LanguageClient(
@@ -48,23 +47,3 @@ export class FortranLangServer {
4847
return capabilities
4948
}
5049
}
51-
52-
export function checkForLangServer(config) {
53-
const useLangServer = false //config.get('useLanguageServer')
54-
if (!useLangServer) return false
55-
if (process.platform === 'win32') {
56-
vscode.window.showInformationMessage(
57-
'The Fortran language server is not supported on Windows yet.'
58-
)
59-
return false
60-
}
61-
let langServerAvailable = getBinPath(LANG_SERVER_TOOL_ID)
62-
if (!langServerAvailable) {
63-
promptForMissingTool(LANG_SERVER_TOOL_ID)
64-
vscode.window.showInformationMessage(
65-
'Reload VS Code window after installing the Fortran language server'
66-
)
67-
}
68-
return true
69-
}
70-

src/lib/helper.ts

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as fs from 'fs';
22
import * as vscode from 'vscode';
3+
import { installPythonTool } from './tools';
34
import intrinsics from './fortran-intrinsics';
4-
import { installTool, LANG_SERVER_TOOL_ID } from './tools';
5+
import { LoggingService } from '../services/logging-service';
56

67
// IMPORTANT: this should match the value
78
// on the package.json otherwise the extension won't
89
// work at all
9-
export const LANGUAGE_ID = 'FortranFreeForm';
10-
export const FORTRAN_FREE_FORM_ID = { language: LANGUAGE_ID, scheme: 'file' };
10+
export const FORTRAN_DOCUMENT_SELECTOR = [
11+
{ scheme: 'file', language: 'FortranFreeForm' },
12+
{ scheme: 'file', language: 'FortranFixedForm' }
13+
];
1114
export { intrinsics }
1215
export const EXTENSION_ID = 'fortran';
1316

@@ -109,25 +112,51 @@ export function isPositionInString(
109112
let saveKeywordToJson = keyword => {
110113
let doc = _loadDocString(keyword);
111114
let docObject = JSON.stringify({ keyword: keyword, docstr: doc });
112-
fs.appendFile('src/docs/' + keyword + '.json', docObject, function(err) {
115+
fs.appendFile('src/docs/' + keyword + '.json', docObject, function (err) {
113116
if (err) throw err;
114117
console.log('Saved!');
115118
});
116119
};
117120

118-
export { default as getBinPath } from './paths'
119121

120-
export function promptForMissingTool(tool: string) {
122+
/**
123+
* Install a package either a Python pip package or a VS Marketplace Extension.
124+
*
125+
* For the Python install supply the name of the package in PyPi
126+
* e.g. fortran-language-server
127+
*
128+
* For the VS Extension to be installed supply the id of the extension
129+
* e.g 'hansec.fortran-ls'
130+
*
131+
* @param tool name of the tool e.g. fortran-language-server
132+
* @param msg optional message for installing said package
133+
* @param toolType type of tool, supports `Python` (through pip) and 'VSExt'
134+
*/
135+
export function promptForMissingTool(tool: string, msg: string, toolType: string, logger?: LoggingService) {
121136
const items = ['Install'];
122-
let message = '';
123-
if (tool === 'fortran-langserver') {
124-
message =
125-
'You choose to use the fortranLanguageServer functionality but it is not installed. Please press the Install button to install it';
126-
}
127-
vscode.window.showInformationMessage(message, ...items).then(selected => {
128-
if (selected === 'Install') {
129-
installTool(tool);
130-
}
137+
return new Promise((resolve, reject) => {
138+
resolve(
139+
vscode.window.showInformationMessage(msg, ...items).then(selected => {
140+
if (selected === 'Install') {
141+
switch (toolType) {
142+
case 'Python':
143+
installPythonTool(tool, logger);
144+
break;
145+
146+
case 'VSExt':
147+
logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`);
148+
vscode.commands.executeCommand('extension.open', tool);
149+
vscode.commands.executeCommand('workbench.extensions.installExtension', tool);
150+
logger.logInfo(`Extension ${tool} successfully installed`);
151+
break;
152+
153+
default:
154+
logger.logError(`Failed to install tool: ${tool}`);
155+
break;
156+
}
157+
}
158+
})
159+
);
131160
});
132161

133162
}

0 commit comments

Comments
 (0)