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' ;
55
66// IMPORTANT: this should match the value
77// on the package.json otherwise the extension won't
88// 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' } ;
1111export { intrinsics }
12- export const EXTENSION_ID = 'fortran'
12+ export const EXTENSION_ID = 'fortran' ;
1313
1414export const FORTRAN_KEYWORDS = [
1515 'FUNCTION' ,
@@ -23,46 +23,46 @@ export const FORTRAN_KEYWORDS = [
2323 'ELIF' ,
2424 'END' ,
2525 'IMPLICIT' ,
26- ]
26+ ] ;
2727
2828export const isIntrinsic = keyword => {
2929 return (
3030 intrinsics . findIndex ( intrinsic => intrinsic === keyword . toUpperCase ( ) ) !==
3131 - 1
32- )
33- }
32+ ) ;
33+ } ;
3434
3535interface Doc {
36- keyword : string
37- docstr : string
36+ keyword : string ;
37+ docstr : string ;
3838}
3939
4040export 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+ } ;
4747
4848export const _loadDocString = ( keyword : string ) => {
49- keyword = keyword . toUpperCase ( )
49+ keyword = keyword . toUpperCase ( ) ;
5050
5151 let docStringBuffer = fs . readFileSync (
5252 __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;
6262
6363 docText = docText
6464 . replace ( varRegex , ( match , code : string ) => {
65- return '`' + code + '`'
65+ return '`' + code + '`' ;
6666 } )
6767 . replace ( spanRegex , ( match , code ) => `*${ code } *` )
6868 . replace ( defListRegex , ( match , entry , def ) => `**${ entry } ** ${ def } \n` )
@@ -72,65 +72,65 @@ export const _loadDocString = (keyword: string) => {
7272 . replace ( / < t b o d y \s * .* ?> ( [ \s \w < > \/ \W ] + ?) < \/ t b o d y > / g, ( match , code ) => code )
7373 . replace ( tableRegex , ( match , code ) => code )
7474 . replace ( codeRegex , ( match , code : string ) => {
75- return '`' + code + '`'
75+ return '`' + code + '`' ;
7676 } )
7777 . replace ( / < p > \s * ?/ g, '\n' )
7878 . replace ( / < \/ p > \s * ?/ g, '\n' )
7979 . 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+ } ;
8888
8989export const getIncludeParams = ( paths : string [ ] ) => {
9090 if ( paths . length === 0 ) {
91- return ''
91+ return '' ;
9292 }
93- return '-I ' + paths . join ( ' ' )
94- }
93+ return '-I ' + paths . join ( ' ' ) ;
94+ } ;
9595
9696export function isPositionInString (
9797 document : vscode . TextDocument ,
9898 position : vscode . Position
9999) : 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 ) ;
102102
103103 // 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 ;
105105 let escapedDoubleQuotesCnt = ( lineTillCurrentPosition . match ( / \\ \" / g) || [ ] )
106- . length
106+ . length ;
107107
108- doubleQuotesCnt -= escapedDoubleQuotesCnt
109- return doubleQuotesCnt % 2 === 1
108+ doubleQuotesCnt -= escapedDoubleQuotesCnt ;
109+ return doubleQuotesCnt % 2 === 1 ;
110110}
111111
112112let 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 } ) ;
115115 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+ } ;
120120
121121export { default as getBinPath } from './paths'
122122
123123export function promptForMissingTool ( tool : string ) {
124- const items = [ 'Install' ]
125- let message = ''
124+ const items = [ 'Install' ] ;
125+ let message = '' ;
126126 if ( tool === 'fortran-langserver' ) {
127127 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' ;
129129 }
130130 vscode . window . showInformationMessage ( message , ...items ) . then ( selected => {
131131 if ( selected === 'Install' ) {
132- installTool ( tool )
132+ installTool ( tool ) ;
133133 }
134- } )
134+ } ) ;
135135
136136}
0 commit comments