Skip to content

Commit

Permalink
Add experimental support for code assistance using a language server (#…
Browse files Browse the repository at this point in the history
…90)

Added basic support for using the language sever protocol with the [fortran-languague-server](https://github.com/hansec/fortran-language-server)
This is still an experimental feature and contains several bugs. But the idea is to get it out there as fast as possible and fix the bug later on.
  • Loading branch information
krvajal authored Oct 14, 2018
1 parent ff2620c commit 02e24e1
Show file tree
Hide file tree
Showing 9 changed files with 582 additions and 518 deletions.
73 changes: 42 additions & 31 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,114 +6,125 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
* Syntax highlight for 'forall' construct (#82)

### Added

- Syntax highlight for `forall` construct (#82)
- Add experimental support for the [Fortran Language Server](https://github.com/hansec/fortran-language-server)

### Changed

- Updated the minimum supported version of VS Code to 1.22.0

## [1.3.1] - 2018-06-26

### Fixed
* Subroutine and function on symbol list were failing with more than one line arguments (#71)
* Minor syntax highlighting issues (#62, #73)

### Added
* Implementation of OpenMP directives highlighting (#17)
* Syntax highlight on multiple line of dummy arguments
- Subroutine and function on symbol list were failing with more than one line arguments (#71)
- Minor syntax highlighting issues (#62, #73)

### Added

- Implementation of OpenMP directives highlighting (#17)
- Syntax highlight on multiple line of dummy arguments

## [1.2.0] - 2018-05-25

### Fixed
* Linter was broken in previous version (#55)
* Symbol listing was failing for subroutine without brackets (#61)

- Linter was broken in previous version (#55)
- Symbol listing was failing for subroutine without brackets (#61)

### Added
* Improved indentation rules (#57)
* Better syntax highlighting of module names (#51)

- Improved indentation rules (#57)
- Better syntax highlighting of module names (#51)

## [1.1.0] - 2018-04-16

### Fixed

* Regression bug in the last release (#44)
- Regression bug in the last release (#44)

### Added

* Improvements on preprocessor directives highlighting
- Improvements on preprocessor directives highlighting

## [1.0.1] - 2018-03-19

### Fixed

* Syntax highlighting issues (#32, #34, #36, #37, #38, #39, #41 )
- Syntax highlighting issues (#32, #34, #36, #37, #38, #39, #41 )

## [0.6.3] - 2018-01-27

### Added

* Configuration option to set types of symbols shown
- Configuration option to set types of symbols shown

### Fixed

* Implementation of the symbol provider now returns a promise (Fixes #21)
* Symbol provider now ignores case when searching for subroutines
- Implementation of the symbol provider now returns a promise (Fixes #21)
- Symbol provider now ignores case when searching for subroutines

## [0.6.2] - 2018-01-01

### Added

* Autoindentation rules for code blocks (thx @graceyangfan for the feature request)
- Autoindentation rules for code blocks (thx @graceyangfan for the feature request)

### Fixed

* Fixed some highlighting issues by @pedro-ricardo
- Fixed some highlighting issues by @pedro-ricardo

## [0.5.2] - 2017-07-14

### Fixed

* A bug in the regex to parse output errors from gfortran
* Now the spawn command uses the directory of the file `gfortran` is analyzing
- A bug in the regex to parse output errors from gfortran
- Now the spawn command uses the directory of the file `gfortran` is analyzing

## [0.5.1] - 2017-07-06

### Added

* Add `Go -> Go to symbol in file` command support for functions
- Add `Go -> Go to symbol in file` command support for functions

## [0.5.0] - 2017-07-06

### Added

* Add code autocompletion for intrinsic and in document declared functions
- Add code autocompletion for intrinsic and in document declared functions

## [0.4.6] - 2017-07-04

### Added

* Add support for user configuration settings
- Add support for user configuration settings

## [0.4.5] - 2017-07-04

### Fixed

* Fix intrinsic functions docs not loading
- Fix intrinsic functions docs not loading

## [0.4.4] - 2017-07-03

### Added

* Add support for old fortran languague
- Add support for old fortran languague
### Fixed
* Fix bug #1
- Fix bug #1

## [0.4.0] - 2017-05-29

### Added

* Show docs for intrinsic functions on hover
- Show docs for intrinsic functions on hover
### Changed
* Updated icon for the extension
* Fix bug on linter not working
- Updated icon for the extension
- Fix bug on linter not working

## [Unreleased]

* Initial release
- Initial release
Binary file added doc/lang_server_type_autocompletion.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "1.3.1",
"publisher": "krvajalm",
"engines": {
"vscode": "^1.19.0"
"vscode": "^1.22.0"
},
"icon": "images/icon.png",
"repository": {
Expand Down Expand Up @@ -129,14 +129,19 @@
],
"description": "Specify what kind of symbols should be shown by the symbols' provider"
},
"fortran.useLanguageServer": {
"type": "boolean",
"default": true,
"description": "Experimental: Not available in Windows. Use Fortran language server from hansec for Hover, Definition, Find All References, Signature Help, File Outline and Workspace Symbol features"
},
"fortran.preferredCase": {
"type": "string",
"default": "lowercase",
"enum": [
"lowercase",
"uppercase"
],
"description": "Scpecify the word case to use when suggesting autocomplete options (One of 'lowercase' or 'upercase')"
"description": "Specify the word case to use when suggesting autocomplete options (One of 'lowercase' or 'upercase')"
}
}
}
Expand All @@ -163,7 +168,7 @@
"remap-istanbul": "^0.8.4",
"tslint": "^4.0.2",
"typescript": "^2.0.3",
"vscode": "^1.0.3"
"vscode": "^1.1.21"
},
"husky": {
"hooks": {
Expand All @@ -174,5 +179,8 @@
"*.ts": [
"prettier --write"
]
},
"dependencies": {
"vscode-languageclient": "^5.1.0"
}
}
18 changes: 16 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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 { LANGUAGE_ID } from './lib/helper'
import { FORTRAN_FREE_FORM_ID } from './lib/helper'
import { FortranLangServer } from './lang-server'
import { ConfigurationFeature } from 'vscode-languageclient/lib/configuration'

const FORTRAN_FREE_FORM_ID = { language: LANGUAGE_ID, scheme: 'file' }

export function activate(context: vscode.ExtensionContext) {
let hoverProvider = new FortranHoverProvider()
let completionProvider = new FortranCompletionProvider()
let symbolProvider = new FortranDocumentSymbolProvider()

const extensionConfig = vscode.workspace.getConfiguration('LANGUAGE_ID')

if (extensionConfig.get('linterEnabled', true)) {
Expand All @@ -31,4 +33,16 @@ export function activate(context: vscode.ExtensionContext) {
FORTRAN_FREE_FORM_ID,
symbolProvider
)
if (extensionConfig.get('useLanguageServer')) {
const langServer = new FortranLangServer(context, extensionConfig)
langServer.start()
langServer.onReady().then(() => {
const capabilities = langServer.getCapabilities()
if (!capabilities) {
return vscode.window.showErrorMessage(
'The language server is not able to serve any features at the moment.'
)
}
})
}
}
2 changes: 2 additions & 0 deletions src/features/completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs'
import * as vscode from 'vscode'
import { isPositionInString, intrinsics, FORTRAN_KEYWORDS } from '../lib/helper'
import { getDeclaredFunctions } from '../lib/functions'

import { EXTENSION_ID } from '../lib/helper'

class CaseCoverter {
Expand Down Expand Up @@ -153,5 +154,6 @@ export class FortranCompletionProvider
)
}
return currentWord

}
}
45 changes: 45 additions & 0 deletions src/lang-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
LanguageClient,
LanguageClientOptions,
Executable,
} from 'vscode-languageclient'
import { getBinPath, FORTRAN_FREE_FORM_ID } from './lib/helper'

class FortranLangServer {
c: LanguageClient
constructor(context, config) {
let langServerFlags: string[] = config.get('languageServerFlags', [])

const serverOptions: Executable = {
command: getBinPath('fortran-langserver'),
args: [...langServerFlags],
options: {},
}

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

this.c = new LanguageClient(
'fortran-langserver',
serverOptions,
clientOptions
)
}

start() {
this.c.start()
}

onReady() {
return this.c.onReady()
}

getCapabilities() {
const capabilities =
this.c.initializeResult && this.c.initializeResult.capabilities
return capabilities
}
}

export { FortranLangServer }
Loading

0 comments on commit 02e24e1

Please sign in to comment.