Skip to content

Updates #274

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 13 commits into from
Nov 9, 2021
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Installing Extension
run: yarn install
- name: Compile
run: yarn compile
- name: Test Syntax Highlighting
run: yarn test:grammar
- name: Test Unittests
Expand Down
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [2.4.2]

### Fixed

- Extension now activates for `FortranFixedForm`
([#257](https://github.com/krvajal/vscode-fortran-support/issues/257))
- Linting is now operational for `FortranFixedForm`
([#258](https://github.com/krvajal/vscode-fortran-support/issues/258))

### Changed

- Renamed the Fixed Format Format language from `fortran_fixed-form` to
`FortranFixedForm`, an alias has been added for backwards compatibility
([#259](https://github.com/krvajal/vscode-fortran-support/issues/259))

### Removed

- Removes `paths.js` for detecting binaries in favour of `which`

## [2.4.1]

### Fixed

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

- Initial release

[unreleased]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.0...HEAD
[unreleased]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.2...HEAD
[2.4.2]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.1...v2.4.2
[2.4.1]: https://github.com/krvajal/vscode-fortran-support/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/krvajal/vscode-fortran-support/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/krvajal/vscode-fortran-support/compare/v2.2.2...v2.3.0
[2.2.2]: https://github.com/krvajal/vscode-fortran-support/compare/2.2.1...v2.2.1
Expand Down
3,635 changes: 1,747 additions & 1,888 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"engines": {
"vscode": "^1.30.x"
"vscode": "^1.52.x"
},
"icon": "images/icon.png",
"homepage": "https://github.com/krvajalmiguelangel/vscode-fortran-support",
Expand All @@ -39,7 +39,8 @@
"Debuggers"
],
"activationEvents": [
"onLanguage:FortranFreeForm"
"onLanguage:FortranFreeForm",
"onLanguage:FortranFixedForm"
],
"main": "./out/src/extension",
"extensionDependencies": [
Expand Down Expand Up @@ -72,11 +73,12 @@
"configuration": "./language-configuration.json"
},
{
"id": "fortran_fixed-form",
"id": "FortranFixedForm",
"aliases": [
"Fortran",
"fortran",
"FORTRAN77"
"FORTRAN77",
"fortran_fixed-form"
],
"extensions": [
".f",
Expand Down Expand Up @@ -110,7 +112,7 @@
]
},
{
"language": "fortran_fixed-form",
"language": "FortranFixedForm",
"scopeName": "source.fortran.fixed",
"path": "./syntaxes/fortran_fixed-form.tmLanguage.json"
}
Expand Down Expand Up @@ -201,7 +203,7 @@
"language": "FortranFreeForm"
},
{
"language": "fortran_fixed-form"
"language": "FortranFixedForm"
}
]
},
Expand Down Expand Up @@ -245,6 +247,7 @@
]
},
"dependencies": {
"vscode-languageclient": "^7.0.0"
"vscode-languageclient": "^7.0.0",
"which": "^2.0.2"
}
}
41 changes: 34 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// src/extension.ts
import * as which from 'which'
import * as vscode from 'vscode'

import FortranLintingProvider from './features/linter-provider'
import FortranHoverProvider from './features/hover-provider'
import { FortranCompletionProvider } from './features/completion-provider'
import { FortranDocumentSymbolProvider } from './features/document-symbol-provider'

import { FORTRAN_FREE_FORM_ID, EXTENSION_ID } from './lib/helper'
import { FortranLangServer, checkForLangServer } from './lang-server'
import { FortranLangServer } from './lang-server'
import { FORTRAN_DOCUMENT_SELECTOR, EXTENSION_ID, promptForMissingTool } from './lib/helper'
import { LoggingService } from './services/logging-service'
import * as pkg from '../package.json'
import { LANG_SERVER_TOOL_ID } from './lib/tools'

export function activate(context: vscode.ExtensionContext) {
const loggingService = new LoggingService()
Expand All @@ -21,15 +23,16 @@ export function activate(context: vscode.ExtensionContext) {
if (extensionConfig.get('linterEnabled', true)) {
let linter = new FortranLintingProvider(loggingService)
linter.activate(context.subscriptions)
vscode.languages.registerCodeActionsProvider(FORTRAN_FREE_FORM_ID, linter)
vscode.languages.registerCodeActionsProvider(FORTRAN_DOCUMENT_SELECTOR, linter)
loggingService.logInfo('Linter is enabled')
} else {
loggingService.logInfo('Linter is not enabled')
}

if (extensionConfig.get('provideCompletion', true)) {
let completionProvider = new FortranCompletionProvider(loggingService)
vscode.languages.registerCompletionItemProvider(
FORTRAN_FREE_FORM_ID,
FORTRAN_DOCUMENT_SELECTOR,
completionProvider
)
} else {
Expand All @@ -38,22 +41,46 @@ export function activate(context: vscode.ExtensionContext) {

if (extensionConfig.get('provideHover', true)) {
let hoverProvider = new FortranHoverProvider(loggingService)
vscode.languages.registerHoverProvider(FORTRAN_FREE_FORM_ID, hoverProvider)
vscode.languages.registerHoverProvider(FORTRAN_DOCUMENT_SELECTOR, hoverProvider)
loggingService.logInfo('Hover Provider is enabled')
} else {
loggingService.logInfo('Hover Provider is not enabled')
}

if (extensionConfig.get('provideSymbols', true)) {
let symbolProvider = new FortranDocumentSymbolProvider()
vscode.languages.registerDocumentSymbolProvider(
FORTRAN_FREE_FORM_ID,
FORTRAN_DOCUMENT_SELECTOR,
symbolProvider
)
loggingService.logInfo('Symbol Provider is enabled')
} else {
loggingService.logInfo('Symbol Provider is not enabled')
}

if (checkForLangServer(extensionConfig)) {
// Check if the language server is installed and if not prompt to install it
if (!which.sync('fortls', { nothrow: true })) {
let msg = `It is highly recommended to use the fortran-language-server to
enable hover, peeking, gotos and many more.
For a full list of features the language server adds see:
https://github.com/hansec/fortran-language-server`;
promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService);
}

// Check that Fortran Intellisense is installed and if not prompt to install
if (!vscode.extensions.getExtension('hansec.fortran-ls')) {
let msg = `It is highly recommended to install the Fortran IntelliSense
extension. The extension is used to interface with the
fortran-language-server.
For a full list of features provided by the extension see:
https://github.com/hansec/vscode-fortran-ls`;
promptForMissingTool('hansec.fortran-ls', msg, 'VSExt', loggingService);
}

// Our interface with `fortls` has been disabled in favour of the @hansec's
// VS Code extension Fortran IntelliSense
const useInternalFLInterface = false;
if (useInternalFLInterface) {
const langServer = new FortranLangServer(context, extensionConfig)
langServer.start()
langServer.onReady().then(() => {
Expand Down
11 changes: 6 additions & 5 deletions src/features/linter-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

import * as path from 'path'
import * as cp from 'child_process'
import { getIncludeParams, LANGUAGE_ID } from '../lib/helper'
import { FORTRAN_DOCUMENT_SELECTOR, getIncludeParams } from '../lib/helper'

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

export default class FortranLintingProvider {
constructor(private loggingService: LoggingService) {}
constructor(private loggingService: LoggingService) { }

private diagnosticCollection: vscode.DiagnosticCollection

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

// Only lint Fortran (free, fixed) format files
if (
textDocument.languageId !== LANGUAGE_ID ||
textDocument.uri.scheme !== 'file'
!FORTRAN_DOCUMENT_SELECTOR.some(e => e.scheme === textDocument.uri.scheme) ||
!FORTRAN_DOCUMENT_SELECTOR.some(e => e.language === textDocument.languageId)
) {
return
}
Expand Down Expand Up @@ -137,7 +138,7 @@ export default class FortranLintingProvider {
private command: vscode.Disposable

public activate(subscriptions: vscode.Disposable[]) {
this.diagnosticCollection = vscode.languages.createDiagnosticCollection()
this.diagnosticCollection = vscode.languages.createDiagnosticCollection('Fortran')

vscode.workspace.onDidOpenTextDocument(
this.doModernFortranLint,
Expand Down
29 changes: 4 additions & 25 deletions src/lang-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import {
LanguageClientOptions,
Executable,
} from 'vscode-languageclient/node'
import * as which from 'which'
import * as vscode from 'vscode'
import {
getBinPath,
FORTRAN_FREE_FORM_ID,
promptForMissingTool,
FORTRAN_DOCUMENT_SELECTOR,
} from './lib/helper'
import { LANG_SERVER_TOOL_ID } from './lib/tools'

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

const serverOptions: Executable = {
command: getBinPath(LANG_SERVER_TOOL_ID),
command: which.sync(LANG_SERVER_TOOL_ID),
args: [...langServerFlags],
options: {},
}

const clientOptions: LanguageClientOptions = {
documentSelector: [FORTRAN_FREE_FORM_ID],
documentSelector: FORTRAN_DOCUMENT_SELECTOR,
}

this.c = new LanguageClient(
Expand All @@ -48,23 +47,3 @@ export class FortranLangServer {
return capabilities
}
}

export function checkForLangServer(config) {
const useLangServer = false //config.get('useLanguageServer')
if (!useLangServer) return false
if (process.platform === 'win32') {
vscode.window.showInformationMessage(
'The Fortran language server is not supported on Windows yet.'
)
return false
}
let langServerAvailable = getBinPath(LANG_SERVER_TOOL_ID)
if (!langServerAvailable) {
promptForMissingTool(LANG_SERVER_TOOL_ID)
vscode.window.showInformationMessage(
'Reload VS Code window after installing the Fortran language server'
)
}
return true
}

59 changes: 44 additions & 15 deletions src/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as fs from 'fs';
import * as vscode from 'vscode';
import { installPythonTool } from './tools';
import intrinsics from './fortran-intrinsics';
import { installTool, LANG_SERVER_TOOL_ID } from './tools';
import { LoggingService } from '../services/logging-service';

// IMPORTANT: this should match the value
// on the package.json otherwise the extension won't
// work at all
export const LANGUAGE_ID = 'FortranFreeForm';
export const FORTRAN_FREE_FORM_ID = { language: LANGUAGE_ID, scheme: 'file' };
export const FORTRAN_DOCUMENT_SELECTOR = [
{ scheme: 'file', language: 'FortranFreeForm' },
{ scheme: 'file', language: 'FortranFixedForm' }
];
export { intrinsics }
export const EXTENSION_ID = 'fortran';

Expand Down Expand Up @@ -109,25 +112,51 @@ export function isPositionInString(
let saveKeywordToJson = keyword => {
let doc = _loadDocString(keyword);
let docObject = JSON.stringify({ keyword: keyword, docstr: doc });
fs.appendFile('src/docs/' + keyword + '.json', docObject, function(err) {
fs.appendFile('src/docs/' + keyword + '.json', docObject, function (err) {
if (err) throw err;
console.log('Saved!');
});
};

export { default as getBinPath } from './paths'

export function promptForMissingTool(tool: string) {
/**
* Install a package either a Python pip package or a VS Marketplace Extension.
*
* For the Python install supply the name of the package in PyPi
* e.g. fortran-language-server
*
* For the VS Extension to be installed supply the id of the extension
* e.g 'hansec.fortran-ls'
*
* @param tool name of the tool e.g. fortran-language-server
* @param msg optional message for installing said package
* @param toolType type of tool, supports `Python` (through pip) and 'VSExt'
*/
export function promptForMissingTool(tool: string, msg: string, toolType: string, logger?: LoggingService) {
const items = ['Install'];
let message = '';
if (tool === 'fortran-langserver') {
message =
'You choose to use the fortranLanguageServer functionality but it is not installed. Please press the Install button to install it';
}
vscode.window.showInformationMessage(message, ...items).then(selected => {
if (selected === 'Install') {
installTool(tool);
}
return new Promise((resolve, reject) => {
resolve(
vscode.window.showInformationMessage(msg, ...items).then(selected => {
if (selected === 'Install') {
switch (toolType) {
case 'Python':
installPythonTool(tool, logger);
break;

case 'VSExt':
logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`);
vscode.commands.executeCommand('extension.open', tool);
vscode.commands.executeCommand('workbench.extensions.installExtension', tool);
logger.logInfo(`Extension ${tool} successfully installed`);
break;

default:
logger.logError(`Failed to install tool: ${tool}`);
break;
}
}
})
);
});

}
Loading