Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit 02169ec

Browse files
authored
FUSETOOLS2-1010 - working on some sonar code smells (#431)
* FUSETOOLS2-1010 - working on some sonar code smells * additional updates * fixing errant merge issue * removing unneeded await Signed-off-by: Brian Fitzpatrick <[email protected]>
1 parent 6293aa0 commit 02169ec

File tree

9 files changed

+91
-106
lines changed

9 files changed

+91
-106
lines changed

src/commandHandler.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import * as vscode from 'vscode';
1919
import * as path from 'path';
20-
import {getValue} from './utils';
20+
import {getValue, isDefaultNotificationDisabled} from './utils';
2121
import * as extensionFunctions from './extensionFunctions';
22-
import {isDefaultNotificationDisabled} from './utils';
22+
2323
const url = require('url-parse');
2424

2525
// take the incoming didact link and allow a mix of a uri and text/user inputs
@@ -132,10 +132,9 @@ function handleSrcFilePath(srcFilePath: string, extensionPath : string) : vscode
132132
if (extensionPath === undefined) {
133133
return undefined;
134134
}
135-
const uri : vscode.Uri = vscode.Uri.file(
135+
return vscode.Uri.file(
136136
path.resolve(extensionPath, srcFilePath)
137137
);
138-
return uri;
139138
}
140139

141140
// take a "extFilePath=" or "extension=" extId/filepath
@@ -152,10 +151,9 @@ export function handleExtFilePath(extFilePath: string) : vscode.Uri | undefined
152151
const pathToAdd = array.join(separator);
153152
const extensionPath = ext.extensionPath;
154153
extensionFunctions.sendTextToOutputChannel(`-- combining ${pathToAdd} ${extensionPath}`);
155-
const uri : vscode.Uri = vscode.Uri.file(
154+
return vscode.Uri.file(
156155
path.resolve(extensionPath, pathToAdd)
157156
);
158-
return uri;
159157
}
160158
}
161159
}
@@ -205,7 +203,7 @@ async function handleUser(text : string, outputs : string[], errorMessage : stri
205203

206204
// get a single input
207205
async function getUserInput(prompt:string): Promise<string | undefined> {
208-
return await vscode.window.showInputBox({
206+
return vscode.window.showInputBox({
209207
prompt: `Enter a ${prompt}`,
210208
placeHolder: prompt
211209
});

src/didactManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ export class DidactManager {
105105

106106
public getByUri(testUri: Uri): DidactPanel | undefined {
107107
let returnPanel = undefined;
108-
for (let index = 0; index < this._panels.length; index++) {
109-
const p = this._panels[index];
108+
for ( let p of this._panels.values()) {
110109
const originalUri = p.getDidactUriPath();
111110
if (testUri && originalUri && originalUri.toString() === testUri.toString()) {
112111
returnPanel = p;

src/didactPanel.ts

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,50 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as vscode from 'vscode';
1918
import * as extensionFunctions from './extensionFunctions';
2019
import * as path from 'path';
21-
import { ViewColumn } from 'vscode';
20+
import { ViewColumn, WebviewPanel, Disposable, Uri, workspace, window, ExtensionContext, extensions } from 'vscode';
2221
import { DIDACT_DEFAULT_URL } from './utils';
2322
import { DEFAULT_TITLE_VALUE, didactManager, VIEW_TYPE } from './didactManager';
2423
import * as commandHandler from './commandHandler';
2524

2625
export class DidactPanel {
2726

2827
// public for testing purposes
29-
public _panel: vscode.WebviewPanel | undefined;
28+
public _panel: WebviewPanel | undefined;
3029

31-
private _disposables: vscode.Disposable[] = [];
30+
private _disposables: Disposable[] = [];
3231
private currentHtml : string | undefined = undefined;
33-
private didactUriPath : vscode.Uri | undefined = undefined;
32+
private didactUriPath : Uri | undefined = undefined;
3433
private defaultTitle = DEFAULT_TITLE_VALUE;
3534
private isAsciiDoc = false;
3635
private _disposed = false;
3736
public visible = false;
3837

39-
public constructor(uri?: vscode.Uri ) {
38+
public constructor(uri?: Uri ) {
4039
this.didactUriPath = uri;
4140
didactManager.add(this);
4241
}
4342

44-
public initWebviewPanel(viewColumn: ViewColumn, inpath?: vscode.Uri | undefined): DidactPanel | undefined {
43+
public initWebviewPanel(viewColumn: ViewColumn, inpath?: Uri | undefined): DidactPanel | undefined {
4544
const extPath = didactManager.getExtensionPath();
4645
if (!extPath) {
4746
console.error(`Error: Extension context not set on Didact manager`);
4847
return undefined;
4948
}
5049

5150
// Otherwise, create a new panel.
52-
const localResourceRoots = [vscode.Uri.file(path.resolve(extPath, 'media'))];
51+
const localResourceRoots = [Uri.file(path.resolve(extPath, 'media'))];
5352
if (inpath) {
5453
const dirName = path.dirname(inpath.fsPath);
55-
localResourceRoots.push(vscode.Uri.file(dirName));
54+
localResourceRoots.push(Uri.file(dirName));
5655
}
5756

58-
const localIconPath = vscode.Uri.file(path.resolve(extPath, 'icon/logo.svg'));
57+
const localIconPath = Uri.file(path.resolve(extPath, 'icon/logo.svg'));
5958
const iconDirPath = path.dirname(localIconPath.fsPath);
60-
localResourceRoots.push(vscode.Uri.file(iconDirPath));
59+
localResourceRoots.push(Uri.file(iconDirPath));
6160

62-
const panel = vscode.window.createWebviewPanel(
61+
const panel = window.createWebviewPanel(
6362
VIEW_TYPE, this.defaultTitle, viewColumn,
6463
{
6564
// Enable javascript in the webview
@@ -77,7 +76,7 @@ export class DidactPanel {
7776
return this.attachWebviewPanel(panel);
7877
}
7978

80-
public attachWebviewPanel(webviewPanel: vscode.WebviewPanel): DidactPanel {
79+
public attachWebviewPanel(webviewPanel: WebviewPanel): DidactPanel {
8180
this._panel = webviewPanel;
8281
this.setVisible(webviewPanel.active);
8382
this._panel.onDidDispose(() => {
@@ -91,12 +90,12 @@ export class DidactPanel {
9190
this.visible = flag;
9291
}
9392

94-
public static revive(context: vscode.ExtensionContext, webviewPanel: vscode.WebviewPanel, oldBody? : string, oldUri? : string): DidactPanel {
93+
public static revive(context: ExtensionContext, webviewPanel: WebviewPanel, oldBody? : string, oldUri? : string): DidactPanel {
9594
didactManager.setContext(context);
9695

9796
let panel : DidactPanel;
9897
if (oldUri) {
99-
const toUri = vscode.Uri.parse(oldUri);
98+
const toUri = Uri.parse(oldUri);
10099
panel = new DidactPanel(toUri);
101100
} else {
102101
panel = new DidactPanel();
@@ -125,7 +124,7 @@ export class DidactPanel {
125124
try {
126125
await commandHandler.processInputs(message.text, didactManager.getExtensionPath());
127126
} catch (error) {
128-
vscode.window.showErrorMessage(`Didact was unable to call commands: ${message.text}: ${error}`);
127+
window.showErrorMessage(`Didact was unable to call commands: ${message.text}: ${error}`);
129128
}
130129
}
131130
return;
@@ -182,7 +181,7 @@ export class DidactPanel {
182181
return this._panel?.title;
183182
}
184183

185-
public getDidactUriPath(): vscode.Uri | undefined {
184+
public getDidactUriPath(): Uri | undefined {
186185
return this.didactUriPath;
187186
}
188187

@@ -195,7 +194,7 @@ export class DidactPanel {
195194
return this.defaultTitle;
196195
}
197196

198-
public setDidactUriPath(inpath : vscode.Uri | undefined): void {
197+
public setDidactUriPath(inpath : Uri | undefined): void {
199198
this.didactUriPath = inpath;
200199
if (inpath) {
201200
const tempFilename = path.basename(inpath.fsPath);
@@ -231,13 +230,13 @@ export class DidactPanel {
231230
const nonce = this.getNonce();
232231

233232
// Base uri to support images
234-
const didactUri : vscode.Uri = this.didactUriPath as vscode.Uri;
233+
const didactUri : Uri = this.didactUriPath as Uri;
235234

236235
let uriBaseHref = undefined;
237236
if (didactUri && this._panel) {
238237
try {
239238
const didactUriPath = path.dirname(didactUri.fsPath);
240-
const uriBase = this._panel.webview.asWebviewUri(vscode.Uri.file(didactUriPath)).toString();
239+
const uriBase = this._panel.webview.asWebviewUri(Uri.file(didactUriPath)).toString();
241240
uriBaseHref = `<base href="${uriBase}${uriBase.endsWith('/') ? '' : '/'}"/>`;
242241
} catch (error) {
243242
console.error(error);
@@ -251,15 +250,15 @@ export class DidactPanel {
251250
}
252251

253252
// Local path to main script run in the webview
254-
const scriptPathOnDisk = vscode.Uri.file(
253+
const scriptPathOnDisk = Uri.file(
255254
path.resolve(extPath, 'media', 'main.js')
256255
);
257256

258257
// And the uri we use to load this script in the webview
259258
const scriptUri = scriptPathOnDisk.with({ scheme: 'vscode-resource' });
260259

261260
// the cssUri is our path to the stylesheet included in the security policy
262-
const cssPathOnDisk = vscode.Uri.file(
261+
const cssPathOnDisk = Uri.file(
263262
path.resolve(extPath, 'media', 'webviewslim.css')
264263
);
265264
const cssUri = cssPathOnDisk.with({ scheme: 'vscode-resource' });
@@ -270,7 +269,7 @@ export class DidactPanel {
270269
// process the stylesheet details for asciidoc or markdown-based didact files
271270
const stylesheetHtml = this.produceStylesheetHTML(cssUriHtml);
272271

273-
const extensionHandle = vscode.extensions.getExtension(extensionFunctions.EXTENSION_ID);
272+
const extensionHandle = extensions.getExtension(extensionFunctions.EXTENSION_ID);
274273
let didactVersionLabel = 'Didact';
275274
if (extensionHandle) {
276275
const didactVersion = extensionHandle.packageJSON.version;
@@ -294,7 +293,7 @@ export class DidactPanel {
294293
metaHeader += `\n${uriBaseHref}\n`;
295294
}
296295

297-
const completedHtml = `<!DOCTYPE html>
296+
return `<!DOCTYPE html>
298297
<html lang="en">
299298
<head>
300299
${metaHeader}
@@ -310,8 +309,6 @@ export class DidactPanel {
310309
<script nonce="${nonce}" src="${scriptUri}"/>
311310
</body>
312311
</html>`;
313-
314-
return completedHtml;
315312
}
316313

317314
produceStylesheetHTML(cssUriHtml : string) : string {
@@ -372,7 +369,7 @@ export class DidactPanel {
372369
return undefined;
373370
}
374371

375-
getColumn() : vscode.ViewColumn | undefined {
372+
getColumn() : ViewColumn | undefined {
376373
if (this._panel) {
377374
return this._panel.viewColumn;
378375
}
@@ -417,9 +414,9 @@ export class DidactPanel {
417414
}
418415

419416
public hardReset(): void {
420-
const configuredUri : string | undefined = vscode.workspace.getConfiguration().get(DIDACT_DEFAULT_URL);
417+
const configuredUri : string | undefined = workspace.getConfiguration().get(DIDACT_DEFAULT_URL);
421418
if (configuredUri) {
422-
const defaultUri = vscode.Uri.parse(configuredUri);
419+
const defaultUri = Uri.parse(configuredUri);
423420
didactManager.active()?.setDidactUriPath(defaultUri);
424421
}
425422
didactManager.active()?._update(true);

src/extension.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import * as vscode from 'vscode';
1919
import * as extensionFunctions from './extensionFunctions';
2020
import { DidactNodeProvider, TreeNode } from './nodeProvider';
21-
import { registerTutorial, clearRegisteredTutorials, getOpenAtStartupSetting, clearOutputChannels } from './utils';
21+
import { registerTutorialWithCategory, clearRegisteredTutorials, getOpenAtStartupSetting, clearOutputChannels } from './utils';
2222
import { DidactUriCompletionItemProvider } from './didactUriCompletionItemProvider';
2323
import { DidactPanelSerializer } from './didactPanelSerializer';
2424
import { VIEW_TYPE } from './didactManager';
@@ -91,19 +91,19 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
9191

9292
// register the default tutorial
9393
const tutorialUri = vscode.Uri.file(context.asAbsolutePath('./demos/markdown/didact-demo.didact.md'));
94-
await registerTutorial(DEFAULT_TUTORIAL_NAME, tutorialUri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
94+
await registerTutorialWithCategory(DEFAULT_TUTORIAL_NAME, tutorialUri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
9595

9696
// register the tutorial for creating a new extension with a didact file
9797
const tutorial2Uri = vscode.Uri.file(context.asAbsolutePath('./create_extension/create-new-tutorial-with-extension.didact.md'));
98-
await registerTutorial("Create a New Didact Tutorial Extension", tutorial2Uri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
98+
await registerTutorialWithCategory("Create a New Didact Tutorial Extension", tutorial2Uri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
9999

100100
// register the javascript tutorial
101101
const tutorial3Uri = vscode.Uri.file(context.asAbsolutePath('./demos/markdown/helloJS/helloJS.didact.md'));
102-
await registerTutorial("HelloWorld with JavaScript in Three Steps", tutorial3Uri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
102+
await registerTutorialWithCategory("HelloWorld with JavaScript in Three Steps", tutorial3Uri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
103103

104104
// register the didact tutorial
105105
const tutorial4Uri = vscode.Uri.file(context.asAbsolutePath('./demos/markdown/tutorial/tutorial.didact.md'));
106-
await registerTutorial("Writing Your First Didact Tutorial", tutorial4Uri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
106+
await registerTutorialWithCategory("Writing Your First Didact Tutorial", tutorial4Uri.fsPath, DEFAULT_TUTORIAL_CATEGORY);
107107

108108
// create the view
109109
createIntegrationsView();

0 commit comments

Comments
 (0)