1- import { CancellationToken , TextDocument , Position , Hover } from 'vscode' ;
2- import * as fs from 'fs' ;
3- import * as vscode from 'vscode' ;
4- import { isPositionInString , intrinsics , FORTRAN_KEYWORDS } from '../lib/helper' ;
5- import { getDeclaredFunctions } from '../lib/functions' ;
1+ import { CancellationToken , TextDocument , Position , Hover } from 'vscode'
2+ import * as fs from 'fs'
3+ import * as vscode from 'vscode'
4+ import { isPositionInString , intrinsics , FORTRAN_KEYWORDS } from '../lib/helper'
5+ import { getDeclaredFunctions } from '../lib/functions'
66
7- import { EXTENSION_ID } from '../lib/helper' ;
7+ import { EXTENSION_ID } from '../lib/helper'
8+ import { LoggingService } from '../services/logging-service'
89
910class CaseCoverter {
10- preferredCase : string ;
11- static LOWER = 'lowercase' ;
12- static UPPER = 'uppercase' ;
11+ preferredCase : string
12+ static LOWER = 'lowercase'
13+ static UPPER = 'uppercase'
1314
1415 constructor ( preferredCase : string = CaseCoverter . LOWER ) {
15- this . preferredCase = preferredCase ;
16+ this . preferredCase = preferredCase
1617 }
1718
1819 convert ( word : string ) : string {
1920 if ( this . preferredCase === CaseCoverter . LOWER ) {
20- return this . toLower ( word ) ;
21+ return this . toLower ( word )
2122 } else if ( this . preferredCase === CaseCoverter . UPPER ) {
22- return this . toUpper ( word ) ;
23+ return this . toUpper ( word )
2324 }
2425
25- throw new Error ( `the provided case ${ this . preferredCase } is not supported` ) ;
26+ throw new Error ( `the provided case ${ this . preferredCase } is not supported` )
2627 }
2728
2829 toLower ( word : string ) {
29- return word . toLowerCase ( ) ;
30+ return word . toLowerCase ( )
3031 }
3132 toUpper ( word : string ) {
32- return word . toUpperCase ( ) ;
33+ return word . toUpperCase ( )
3334 }
3435}
3536
3637export class FortranCompletionProvider
37- implements vscode . CompletionItemProvider {
38+ implements vscode . CompletionItemProvider
39+ {
40+ constructor ( private loggingService : LoggingService ) { }
3841 public provideCompletionItems (
3942 document : vscode . TextDocument ,
4043 position : vscode . Position ,
@@ -45,7 +48,7 @@ export class FortranCompletionProvider
4548 position ,
4649 token ,
4750 vscode . workspace . getConfiguration ( EXTENSION_ID )
48- ) ;
51+ )
4952 }
5053
5154 public provideCompletionItemsInternal (
@@ -55,105 +58,104 @@ export class FortranCompletionProvider
5558 config : vscode . WorkspaceConfiguration
5659 ) : Thenable < vscode . CompletionItem [ ] > {
5760 return new Promise < vscode . CompletionItem [ ] > ( ( resolve , reject ) => {
58- let lineText = document . lineAt ( position . line ) . text ;
59- let lineTillCurrentPosition = lineText . substr ( 0 , position . character ) ;
61+ let lineText = document . lineAt ( position . line ) . text
62+ let lineTillCurrentPosition = lineText . substr ( 0 , position . character )
6063 // nothing to complete
6164 if ( lineText . match ( / ^ \s * \/ \/ / ) ) {
62- return resolve ( [ ] ) ;
65+ return resolve ( [ ] )
6366 }
6467
65- let inString = isPositionInString ( document , position ) ;
68+ let inString = isPositionInString ( document , position )
6669 if ( ! inString && lineTillCurrentPosition . endsWith ( '"' ) ) {
6770 // completing a string
68- return resolve ( [ ] ) ;
71+ return resolve ( [ ] )
6972 }
7073
71- let currentWord = this . getCurrentWord ( document , position ) ;
74+ let currentWord = this . getCurrentWord ( document , position )
7275
7376 if ( currentWord . match ( / ^ \d + $ / ) ) {
7477 // starts with a number
75- return resolve ( [ ] ) ;
78+ return resolve ( [ ] )
7679 }
7780
78- const caseConverter = new CaseCoverter ( config . get ( 'preferredCase' ) ) ;
81+ const caseConverter = new CaseCoverter ( config . get ( 'preferredCase' ) )
7982
8083 if ( currentWord . length === 0 ) {
81- resolve ( [ ] ) ;
84+ resolve ( [ ] )
8285 }
8386
8487 const intrinsicSuggestions = this . getIntrinsicSuggestions (
8588 currentWord ,
8689 caseConverter
87- ) ;
90+ )
8891
8992 // add keyword suggestions
90- const keywordSuggestions = this . getKeywordSuggestions ( currentWord ) ;
93+ const keywordSuggestions = this . getKeywordSuggestions ( currentWord )
9194
9295 const functionSuggestions = this . getFunctionSuggestions (
9396 document ,
9497 currentWord
95- ) ;
98+ )
9699
97100 return resolve ( [
98101 ...intrinsicSuggestions ,
99102 ...keywordSuggestions ,
100103 ...functionSuggestions ,
101- ] ) ;
102- } ) ;
104+ ] )
105+ } )
103106 }
104107
105108 private getIntrinsicSuggestions (
106109 currentWord : string ,
107110 caseConverter : CaseCoverter
108111 ) : vscode . CompletionItem [ ] {
109112 return intrinsics
110- . filter ( i => i . startsWith ( currentWord . toUpperCase ( ) ) )
113+ . filter ( ( i ) => i . startsWith ( currentWord . toUpperCase ( ) ) )
111114 . map ( ( intrinsic : string ) => {
112115 return new vscode . CompletionItem (
113116 caseConverter . convert ( intrinsic ) ,
114117 vscode . CompletionItemKind . Method
115- ) ;
116- } ) ;
118+ )
119+ } )
117120 }
118121
119122 private getKeywordSuggestions ( currentWord : string ) : vscode . CompletionItem [ ] {
120- return FORTRAN_KEYWORDS . filter ( keyword =>
123+ return FORTRAN_KEYWORDS . filter ( ( keyword ) =>
121124 keyword . startsWith ( currentWord . toUpperCase ( ) )
122- ) . map ( keyword => {
125+ ) . map ( ( keyword ) => {
123126 return new vscode . CompletionItem (
124127 keyword . toLowerCase ( ) ,
125128 vscode . CompletionItemKind . Keyword
126- ) ;
127- } ) ;
129+ )
130+ } )
128131 }
129132
130133 private getFunctionSuggestions (
131134 document : TextDocument ,
132135 currentWord : string
133136 ) : vscode . CompletionItem [ ] {
134- const functions = getDeclaredFunctions ( document ) ;
137+ const functions = getDeclaredFunctions ( document )
135138 // check for available functions
136139 return functions
137- . filter ( fun => fun . name . startsWith ( currentWord ) )
138- . map ( fun => {
140+ . filter ( ( fun ) => fun . name . startsWith ( currentWord ) )
141+ . map ( ( fun ) => {
139142 return new vscode . CompletionItem (
140143 `${ fun . name } (` ,
141144 vscode . CompletionItemKind . Function
142- ) ;
143- } ) ;
145+ )
146+ } )
144147 }
145148
146149 private getCurrentWord ( document : TextDocument , position : Position ) : string {
147- let wordAtPosition = document . getWordRangeAtPosition ( position ) ;
148- let currentWord = '' ;
150+ let wordAtPosition = document . getWordRangeAtPosition ( position )
151+ let currentWord = ''
149152 if ( wordAtPosition && wordAtPosition . start . character < position . character ) {
150- let word = document . getText ( wordAtPosition ) ;
153+ let word = document . getText ( wordAtPosition )
151154 currentWord = word . substr (
152155 0 ,
153156 position . character - wordAtPosition . start . character
154- ) ;
157+ )
155158 }
156- return currentWord ;
157-
159+ return currentWord
158160 }
159161}
0 commit comments