Skip to content

Commit 02e24e1

Browse files
authored
Add experimental support for code assistance using a language server (#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.
1 parent ff2620c commit 02e24e1

File tree

9 files changed

+582
-518
lines changed

9 files changed

+582
-518
lines changed

CHANGELOG.md

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,114 +6,125 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9-
### Added
10-
* Syntax highlight for 'forall' construct (#82)
9+
10+
### Added
11+
12+
- Syntax highlight for `forall` construct (#82)
13+
- Add experimental support for the [Fortran Language Server](https://github.com/hansec/fortran-language-server)
14+
15+
### Changed
16+
17+
- Updated the minimum supported version of VS Code to 1.22.0
1118

1219
## [1.3.1] - 2018-06-26
1320

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

18-
### Added
19-
* Implementation of OpenMP directives highlighting (#17)
20-
* Syntax highlight on multiple line of dummy arguments
23+
- Subroutine and function on symbol list were failing with more than one line arguments (#71)
24+
- Minor syntax highlighting issues (#62, #73)
25+
26+
### Added
27+
28+
- Implementation of OpenMP directives highlighting (#17)
29+
- Syntax highlight on multiple line of dummy arguments
2130

2231
## [1.2.0] - 2018-05-25
2332

2433
### Fixed
25-
* Linter was broken in previous version (#55)
26-
* Symbol listing was failing for subroutine without brackets (#61)
34+
35+
- Linter was broken in previous version (#55)
36+
- Symbol listing was failing for subroutine without brackets (#61)
2737

2838
### Added
29-
* Improved indentation rules (#57)
30-
* Better syntax highlighting of module names (#51)
39+
40+
- Improved indentation rules (#57)
41+
- Better syntax highlighting of module names (#51)
3142

3243
## [1.1.0] - 2018-04-16
3344

3445
### Fixed
3546

36-
* Regression bug in the last release (#44)
47+
- Regression bug in the last release (#44)
3748

3849
### Added
3950

40-
* Improvements on preprocessor directives highlighting
51+
- Improvements on preprocessor directives highlighting
4152

4253
## [1.0.1] - 2018-03-19
4354

4455
### Fixed
4556

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

4859
## [0.6.3] - 2018-01-27
4960

5061
### Added
5162

52-
* Configuration option to set types of symbols shown
63+
- Configuration option to set types of symbols shown
5364

5465
### Fixed
5566

56-
* Implementation of the symbol provider now returns a promise (Fixes #21)
57-
* Symbol provider now ignores case when searching for subroutines
67+
- Implementation of the symbol provider now returns a promise (Fixes #21)
68+
- Symbol provider now ignores case when searching for subroutines
5869

5970
## [0.6.2] - 2018-01-01
6071

6172
### Added
6273

63-
* Autoindentation rules for code blocks (thx @graceyangfan for the feature request)
74+
- Autoindentation rules for code blocks (thx @graceyangfan for the feature request)
6475

6576
### Fixed
6677

67-
* Fixed some highlighting issues by @pedro-ricardo
78+
- Fixed some highlighting issues by @pedro-ricardo
6879

6980
## [0.5.2] - 2017-07-14
7081

7182
### Fixed
7283

73-
* A bug in the regex to parse output errors from gfortran
74-
* Now the spawn command uses the directory of the file `gfortran` is analyzing
84+
- A bug in the regex to parse output errors from gfortran
85+
- Now the spawn command uses the directory of the file `gfortran` is analyzing
7586

7687
## [0.5.1] - 2017-07-06
7788

7889
### Added
7990

80-
* Add `Go -> Go to symbol in file` command support for functions
91+
- Add `Go -> Go to symbol in file` command support for functions
8192

8293
## [0.5.0] - 2017-07-06
8394

8495
### Added
8596

86-
* Add code autocompletion for intrinsic and in document declared functions
97+
- Add code autocompletion for intrinsic and in document declared functions
8798

8899
## [0.4.6] - 2017-07-04
89100

90101
### Added
91102

92-
* Add support for user configuration settings
103+
- Add support for user configuration settings
93104

94105
## [0.4.5] - 2017-07-04
95106

96107
### Fixed
97108

98-
* Fix intrinsic functions docs not loading
109+
- Fix intrinsic functions docs not loading
99110

100111
## [0.4.4] - 2017-07-03
101112

102113
### Added
103114

104-
* Add support for old fortran languague
115+
- Add support for old fortran languague
105116
### Fixed
106-
* Fix bug #1
117+
- Fix bug #1
107118

108119
## [0.4.0] - 2017-05-29
109120

110121
### Added
111122

112-
* Show docs for intrinsic functions on hover
123+
- Show docs for intrinsic functions on hover
113124
### Changed
114-
* Updated icon for the extension
115-
* Fix bug on linter not working
125+
- Updated icon for the extension
126+
- Fix bug on linter not working
116127

117128
## [Unreleased]
118129

119-
* Initial release
130+
- Initial release
864 KB
Loading

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "1.3.1",
66
"publisher": "krvajalm",
77
"engines": {
8-
"vscode": "^1.19.0"
8+
"vscode": "^1.22.0"
99
},
1010
"icon": "images/icon.png",
1111
"repository": {
@@ -129,14 +129,19 @@
129129
],
130130
"description": "Specify what kind of symbols should be shown by the symbols' provider"
131131
},
132+
"fortran.useLanguageServer": {
133+
"type": "boolean",
134+
"default": true,
135+
"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"
136+
},
132137
"fortran.preferredCase": {
133138
"type": "string",
134139
"default": "lowercase",
135140
"enum": [
136141
"lowercase",
137142
"uppercase"
138143
],
139-
"description": "Scpecify the word case to use when suggesting autocomplete options (One of 'lowercase' or 'upercase')"
144+
"description": "Specify the word case to use when suggesting autocomplete options (One of 'lowercase' or 'upercase')"
140145
}
141146
}
142147
}
@@ -163,7 +168,7 @@
163168
"remap-istanbul": "^0.8.4",
164169
"tslint": "^4.0.2",
165170
"typescript": "^2.0.3",
166-
"vscode": "^1.0.3"
171+
"vscode": "^1.1.21"
167172
},
168173
"husky": {
169174
"hooks": {
@@ -174,5 +179,8 @@
174179
"*.ts": [
175180
"prettier --write"
176181
]
182+
},
183+
"dependencies": {
184+
"vscode-languageclient": "^5.1.0"
177185
}
178186
}

src/extension.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import FortranLintingProvider from './features/linter-provider'
55
import FortranHoverProvider from './features/hover-provider'
66
import { FortranCompletionProvider } from './features/completion-provider'
77
import { FortranDocumentSymbolProvider } from './features/document-symbol-provider'
8-
import { LANGUAGE_ID } from './lib/helper'
8+
import { FORTRAN_FREE_FORM_ID } from './lib/helper'
9+
import { FortranLangServer } from './lang-server'
10+
import { ConfigurationFeature } from 'vscode-languageclient/lib/configuration'
911

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

1213
export function activate(context: vscode.ExtensionContext) {
1314
let hoverProvider = new FortranHoverProvider()
1415
let completionProvider = new FortranCompletionProvider()
1516
let symbolProvider = new FortranDocumentSymbolProvider()
17+
1618
const extensionConfig = vscode.workspace.getConfiguration('LANGUAGE_ID')
1719

1820
if (extensionConfig.get('linterEnabled', true)) {
@@ -31,4 +33,16 @@ export function activate(context: vscode.ExtensionContext) {
3133
FORTRAN_FREE_FORM_ID,
3234
symbolProvider
3335
)
36+
if (extensionConfig.get('useLanguageServer')) {
37+
const langServer = new FortranLangServer(context, extensionConfig)
38+
langServer.start()
39+
langServer.onReady().then(() => {
40+
const capabilities = langServer.getCapabilities()
41+
if (!capabilities) {
42+
return vscode.window.showErrorMessage(
43+
'The language server is not able to serve any features at the moment.'
44+
)
45+
}
46+
})
47+
}
3448
}

src/features/completion-provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs'
33
import * as vscode from 'vscode'
44
import { isPositionInString, intrinsics, FORTRAN_KEYWORDS } from '../lib/helper'
55
import { getDeclaredFunctions } from '../lib/functions'
6+
67
import { EXTENSION_ID } from '../lib/helper'
78

89
class CaseCoverter {
@@ -153,5 +154,6 @@ export class FortranCompletionProvider
153154
)
154155
}
155156
return currentWord
157+
156158
}
157159
}

src/lang-server.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
LanguageClient,
3+
LanguageClientOptions,
4+
Executable,
5+
} from 'vscode-languageclient'
6+
import { getBinPath, FORTRAN_FREE_FORM_ID } from './lib/helper'
7+
8+
class FortranLangServer {
9+
c: LanguageClient
10+
constructor(context, config) {
11+
let langServerFlags: string[] = config.get('languageServerFlags', [])
12+
13+
const serverOptions: Executable = {
14+
command: getBinPath('fortran-langserver'),
15+
args: [...langServerFlags],
16+
options: {},
17+
}
18+
19+
const clientOptions: LanguageClientOptions = {
20+
documentSelector: [FORTRAN_FREE_FORM_ID],
21+
}
22+
23+
this.c = new LanguageClient(
24+
'fortran-langserver',
25+
serverOptions,
26+
clientOptions
27+
)
28+
}
29+
30+
start() {
31+
this.c.start()
32+
}
33+
34+
onReady() {
35+
return this.c.onReady()
36+
}
37+
38+
getCapabilities() {
39+
const capabilities =
40+
this.c.initializeResult && this.c.initializeResult.capabilities
41+
return capabilities
42+
}
43+
}
44+
45+
export { FortranLangServer }

0 commit comments

Comments
 (0)