1
- import * as fs from 'fs'
2
- import * as vscode from 'vscode'
3
- import intrinsics from './fortran-intrinsics'
4
- import { installTool } from './tools'
1
+ import * as fs from 'fs' ;
2
+ import * as vscode from 'vscode' ;
3
+ import intrinsics from './fortran-intrinsics' ;
4
+ import { installTool } from './tools' ;
5
5
6
6
// IMPORTANT: this should match the value
7
7
// on the package.json otherwise the extension won't
8
8
// work at all
9
- export const LANGUAGE_ID = 'FortranFreeForm'
10
- export const FORTRAN_FREE_FORM_ID = { language : LANGUAGE_ID , scheme : 'file' }
9
+ export const LANGUAGE_ID = 'FortranFreeForm' ;
10
+ export const FORTRAN_FREE_FORM_ID = { language : LANGUAGE_ID , scheme : 'file' } ;
11
11
export { intrinsics }
12
- export const EXTENSION_ID = 'fortran'
12
+ export const EXTENSION_ID = 'fortran' ;
13
13
14
14
export const FORTRAN_KEYWORDS = [
15
15
'FUNCTION' ,
@@ -23,46 +23,46 @@ export const FORTRAN_KEYWORDS = [
23
23
'ELIF' ,
24
24
'END' ,
25
25
'IMPLICIT' ,
26
- ]
26
+ ] ;
27
27
28
28
export const isIntrinsic = keyword => {
29
29
return (
30
30
intrinsics . findIndex ( intrinsic => intrinsic === keyword . toUpperCase ( ) ) !==
31
31
- 1
32
- )
33
- }
32
+ ) ;
33
+ } ;
34
34
35
35
interface Doc {
36
- keyword : string
37
- docstr : string
36
+ keyword : string ;
37
+ docstr : string ;
38
38
}
39
39
40
40
export const loadDocString = keyword => {
41
- keyword = keyword . toUpperCase ( )
42
- let filepath = __dirname + '/../docs/' + keyword + '.json'
43
- let docstr = fs . readFileSync ( filepath ) . toString ( )
44
- let doc : Doc = JSON . parse ( docstr )
45
- return doc . docstr
46
- }
41
+ keyword = keyword . toUpperCase ( ) ;
42
+ let filepath = __dirname + '/../docs/' + keyword + '.json' ;
43
+ let docstr = fs . readFileSync ( filepath ) . toString ( ) ;
44
+ let doc : Doc = JSON . parse ( docstr ) ;
45
+ return doc . docstr ;
46
+ } ;
47
47
48
48
export const _loadDocString = ( keyword : string ) => {
49
- keyword = keyword . toUpperCase ( )
49
+ keyword = keyword . toUpperCase ( ) ;
50
50
51
51
let docStringBuffer = fs . readFileSync (
52
52
__dirname + '/../../../src/docs/' + keyword + '.html'
53
- )
54
- let docText = docStringBuffer . toString ( )
55
- const codeRegex = / < c o d e > ( .+ ?) < \/ c o d e > \n ? / g
56
- const varRegex = / < v a r > ( .+ ?) < \/ v a r > / g
57
- const spanRegex = / < s a m p > < s p a n c l a s s = " c o m m a n d " > ( \w + ) < \/ s p a n > < \/ s a m p > / g
58
- const tableRegex = / < t a b l e \s * .* > ( [ \s \w < > \/ \W ] + ?) < \/ t a b l e > / g
59
- const codeExampleRegex = / < c o d e c l a s s = " s m a l l e x a m p l e " [ \s \W \w ] * ?> ( [ \s \W \w < > ] * ?) < \/ c o d e > / g
60
- const headerRegex = / ^ * < h ( \d ) > ( .+ ?) < \/ h \1> \n ? / gm
61
- const defListRegex = / < d t > ( [ \w \W ] + ?) < \/ d t > < d d > ( [ \w \W ] + ?) ( < b r > ) ? < \/ d d > / g
53
+ ) ;
54
+ let docText = docStringBuffer . toString ( ) ;
55
+ const codeRegex = / < c o d e > ( .+ ?) < \/ c o d e > \n ? / g;
56
+ const varRegex = / < v a r > ( .+ ?) < \/ v a r > / g;
57
+ const spanRegex = / < s a m p > < s p a n c l a s s = " c o m m a n d " > ( \w + ) < \/ s p a n > < \/ s a m p > / g;
58
+ const tableRegex = / < t a b l e \s * .* > ( [ \s \w < > \/ \W ] + ?) < \/ t a b l e > / g;
59
+ const codeExampleRegex = / < c o d e c l a s s = " s m a l l e x a m p l e " [ \s \W \w ] * ?> ( [ \s \W \w < > ] * ?) < \/ c o d e > / g;
60
+ const headerRegex = / ^ * < h ( \d ) > ( .+ ?) < \/ h \1> \n ? / gm;
61
+ const defListRegex = / < d t > ( [ \w \W ] + ?) < \/ d t > < d d > ( [ \w \W ] + ?) ( < b r > ) ? < \/ d d > / g;
62
62
63
63
docText = docText
64
64
. replace ( varRegex , ( match , code : string ) => {
65
- return '`' + code + '`'
65
+ return '`' + code + '`' ;
66
66
} )
67
67
. replace ( spanRegex , ( match , code ) => `*${ code } *` )
68
68
. replace ( defListRegex , ( match , entry , def ) => `**${ entry } ** ${ def } \n` )
@@ -72,65 +72,65 @@ export const _loadDocString = (keyword: string) => {
72
72
. replace ( / < t b o d y \s * .* ?> ( [ \s \w < > \/ \W ] + ?) < \/ t b o d y > / g, ( match , code ) => code )
73
73
. replace ( tableRegex , ( match , code ) => code )
74
74
. replace ( codeRegex , ( match , code : string ) => {
75
- return '`' + code + '`'
75
+ return '`' + code + '`' ;
76
76
} )
77
77
. replace ( / < p > \s * ?/ g, '\n' )
78
78
. replace ( / < \/ p > \s * ?/ g, '\n' )
79
79
. replace ( headerRegex , ( match , h : string , code : string ) => {
80
- let headerLevel : number = parseInt ( h )
81
- let header = '#' . repeat ( headerLevel )
82
- return `${ header } ${ code } \n`
83
- } )
84
- docText = docText . replace ( / ^ * < b r > \n ? / gm, '\n' ) . replace ( / < \? d l > / g, '' )
85
- console . log ( docText )
86
- return docText
87
- }
80
+ let headerLevel : number = parseInt ( h ) ;
81
+ let header = '#' . repeat ( headerLevel ) ;
82
+ return `${ header } ${ code } \n` ;
83
+ } ) ;
84
+ docText = docText . replace ( / ^ * < b r > \n ? / gm, '\n' ) . replace ( / < \? d l > / g, '' ) ;
85
+ console . log ( docText ) ;
86
+ return docText ;
87
+ } ;
88
88
89
89
export const getIncludeParams = ( paths : string [ ] ) => {
90
90
if ( paths . length === 0 ) {
91
- return ''
91
+ return '' ;
92
92
}
93
- return '-I ' + paths . join ( ' ' )
94
- }
93
+ return '-I ' + paths . join ( ' ' ) ;
94
+ } ;
95
95
96
96
export function isPositionInString (
97
97
document : vscode . TextDocument ,
98
98
position : vscode . Position
99
99
) : boolean {
100
- let lineText = document . lineAt ( position . line ) . text
101
- let lineTillCurrentPosition = lineText . substr ( 0 , position . character )
100
+ let lineText = document . lineAt ( position . line ) . text ;
101
+ let lineTillCurrentPosition = lineText . substr ( 0 , position . character ) ;
102
102
103
103
// Count the number of double quotes in the line till current position. Ignore escaped double quotes
104
- let doubleQuotesCnt = ( lineTillCurrentPosition . match ( / \" / g) || [ ] ) . length
104
+ let doubleQuotesCnt = ( lineTillCurrentPosition . match ( / \" / g) || [ ] ) . length ;
105
105
let escapedDoubleQuotesCnt = ( lineTillCurrentPosition . match ( / \\ \" / g) || [ ] )
106
- . length
106
+ . length ;
107
107
108
- doubleQuotesCnt -= escapedDoubleQuotesCnt
109
- return doubleQuotesCnt % 2 === 1
108
+ doubleQuotesCnt -= escapedDoubleQuotesCnt ;
109
+ return doubleQuotesCnt % 2 === 1 ;
110
110
}
111
111
112
112
let saveKeywordToJson = keyword => {
113
- let doc = _loadDocString ( keyword )
114
- let docObject = JSON . stringify ( { keyword : keyword , docstr : doc } )
113
+ let doc = _loadDocString ( keyword ) ;
114
+ let docObject = JSON . stringify ( { keyword : keyword , docstr : doc } ) ;
115
115
fs . appendFile ( 'src/docs/' + keyword + '.json' , docObject , function ( err ) {
116
- if ( err ) throw err
117
- console . log ( 'Saved!' )
118
- } )
119
- }
116
+ if ( err ) throw err ;
117
+ console . log ( 'Saved!' ) ;
118
+ } ) ;
119
+ } ;
120
120
121
121
export { default as getBinPath } from './paths'
122
122
123
123
export function promptForMissingTool ( tool : string ) {
124
- const items = [ 'Install' ]
125
- let message = ''
124
+ const items = [ 'Install' ] ;
125
+ let message = '' ;
126
126
if ( tool === 'fortran-langserver' ) {
127
127
message =
128
- 'You choose to use the fortranLanguageServer functionality but it is not installed. Please press the Install button to install it'
128
+ 'You choose to use the fortranLanguageServer functionality but it is not installed. Please press the Install button to install it' ;
129
129
}
130
130
vscode . window . showInformationMessage ( message , ...items ) . then ( selected => {
131
131
if ( selected === 'Install' ) {
132
- installTool ( tool )
132
+ installTool ( tool ) ;
133
133
}
134
- } )
134
+ } ) ;
135
135
136
136
}
0 commit comments