Skip to content

Commit 8b521dd

Browse files
authored
feat: add logging via a logging channel (#236)
1 parent 258ba16 commit 8b521dd

File tree

11 files changed

+3550
-211
lines changed

11 files changed

+3550
-211
lines changed

.vscode/tasks.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,33 @@
88

99
// A task runner that calls a custom npm script that compiles the extension.
1010
{
11-
"version": "0.1.0",
11+
"version": "2.0.0",
1212

1313
// we want to run npm
1414
"command": "npm",
1515

16-
// the command is a shell script
17-
"isShellCommand": true,
18-
19-
// show the output window only if unrecognized errors occur.
20-
"showOutput": "silent",
21-
2216
// we run the custom script "compile" as defined in package.json
2317
"args": ["run", "compile", "--loglevel", "silent"],
2418

2519
// The tsc compiler is started in watching mode
2620
"isBackground": true,
2721

2822
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29-
"problemMatcher": "$tsc-watch"
23+
"problemMatcher": "$tsc-watch",
24+
"tasks": [
25+
{
26+
"label": "npm",
27+
"type": "shell",
28+
"command": "npm",
29+
"args": [
30+
"run",
31+
"compile",
32+
"--loglevel",
33+
"silent"
34+
],
35+
"isBackground": true,
36+
"problemMatcher": "$tsc-watch",
37+
"group": "build"
38+
}
39+
]
3040
}

.vscode/tasks.json.old

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Available variables which can be used inside of strings.
2+
// ${workspaceRoot}: the root folder of the team
3+
// ${file}: the current opened file
4+
// ${fileBasename}: the current opened file's basename
5+
// ${fileDirname}: the current opened file's dirname
6+
// ${fileExtname}: the current opened file's extension
7+
// ${cwd}: the current working directory of the spawned process
8+
9+
// A task runner that calls a custom npm script that compiles the extension.
10+
{
11+
"version": "0.1.0",
12+
13+
// we want to run npm
14+
"command": "npm",
15+
16+
// the command is a shell script
17+
"isShellCommand": true,
18+
19+
// show the output window only if unrecognized errors occur.
20+
"showOutput": "silent",
21+
22+
// we run the custom script "compile" as defined in package.json
23+
"args": ["run", "compile", "--loglevel", "silent"],
24+
25+
// The tsc compiler is started in watching mode
26+
"isBackground": true,
27+
28+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29+
"problemMatcher": "$tsc-watch"
30+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
"@types/fs-extra": "0.0.35",
184184
"@types/glob": "^5.0.30",
185185
"@types/mocha": "^2.2.32",
186-
"@types/node": "^6.0.40",
186+
"@types/node": "^15.12.1",
187187
"decache": "^4.1.0",
188188
"fs-extra": "^1.0.0",
189189
"glob": "^7.1.1",

src/extension.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,39 @@ import { FortranDocumentSymbolProvider } from './features/document-symbol-provid
88

99
import { FORTRAN_FREE_FORM_ID, EXTENSION_ID } from './lib/helper'
1010
import { FortranLangServer, checkForLangServer } from './lang-server'
11-
11+
import { LoggingService } from './services/logging-service'
12+
import * as pkg from '../package.json'
1213

1314
export function activate(context: vscode.ExtensionContext) {
14-
15+
const loggingService = new LoggingService()
1516
const extensionConfig = vscode.workspace.getConfiguration(EXTENSION_ID)
1617

18+
loggingService.logInfo(`Extension Name: ${pkg.displayName}`)
19+
loggingService.logInfo(`Extension Version: ${pkg.version}`)
20+
1721
if (extensionConfig.get('linterEnabled', true)) {
18-
let linter = new FortranLintingProvider()
22+
let linter = new FortranLintingProvider(loggingService)
1923
linter.activate(context.subscriptions)
2024
vscode.languages.registerCodeActionsProvider(FORTRAN_FREE_FORM_ID, linter)
25+
} else {
26+
loggingService.logInfo('Linter is not enabled')
2127
}
2228

2329
if (extensionConfig.get('provideCompletion', true)) {
24-
let completionProvider = new FortranCompletionProvider()
30+
let completionProvider = new FortranCompletionProvider(loggingService)
2531
vscode.languages.registerCompletionItemProvider(
2632
FORTRAN_FREE_FORM_ID,
2733
completionProvider
2834
)
35+
} else {
36+
loggingService.logInfo('Completion Provider is not enabled')
2937
}
3038

3139
if (extensionConfig.get('provideHover', true)) {
32-
let hoverProvider = new FortranHoverProvider()
33-
vscode.languages.registerHoverProvider(
34-
FORTRAN_FREE_FORM_ID,
35-
hoverProvider
36-
)
40+
let hoverProvider = new FortranHoverProvider(loggingService)
41+
vscode.languages.registerHoverProvider(FORTRAN_FREE_FORM_ID, hoverProvider)
42+
} else {
43+
loggingService.logInfo('Hover Provider is not enabled')
3744
}
3845

3946
if (extensionConfig.get('provideSymbols', true)) {
@@ -42,10 +49,11 @@ export function activate(context: vscode.ExtensionContext) {
4249
FORTRAN_FREE_FORM_ID,
4350
symbolProvider
4451
)
52+
} else {
53+
loggingService.logInfo('Symbol Provider is not enabled')
4554
}
4655

4756
if (checkForLangServer(extensionConfig)) {
48-
4957
const langServer = new FortranLangServer(context, extensionConfig)
5058
langServer.start()
5159
langServer.onReady().then(() => {

src/features/completion-provider.ts

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
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

910
class 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

3637
export 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

Comments
 (0)