Skip to content

Commit

Permalink
Fix HTML/YML server crash issue (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyaginidhi committed Jul 4, 2024
1 parent 960aa93 commit 090bdf7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/client/PortalWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from "vscode";
import * as path from "path";
import { searchPortalConfigFolder } from "../common/PortalConfigFinder";
import { searchPortalConfigFolder } from "../common/utilities/PathFinderUtil";

/**
* Displays Portal html webpage preview
Expand Down Expand Up @@ -130,7 +130,7 @@ export class PortalWebView {
if (uri) {
// Add bootstrap.min.css
let url = webview.asWebviewUri(
vscode.Uri.joinPath( uri as vscode.Uri, "web-files", "bootstrap.min.css")
vscode.Uri.joinPath(uri as vscode.Uri, "web-files", "bootstrap.min.css")
);
const bootstrap = `<link href="${url}" rel="stylesheet" />`;
html += bootstrap;
Expand Down
3 changes: 2 additions & 1 deletion src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
TransportKind,
WorkspaceFolder,
} from "vscode-languageclient/node";
import { getPortalsOrgURLs, workspaceContainsPortalConfigFolder } from "../common/PortalConfigFinder";
import {
activateDebugger,
deactivateDebugger,
Expand All @@ -41,6 +40,8 @@ import { ActiveOrgOutput } from "./pac/PacTypes";
import { telemetryEventNames } from "./telemetry/TelemetryEventNames";
import { IArtemisAPIOrgResponse } from "../common/services/Interfaces";
import { ArtemisService } from "../common/services/ArtemisService";
import { workspaceContainsPortalConfigFolder } from "../common/utilities/PathFinderUtil";
import { getPortalsOrgURLs } from "../common/utilities/WorkspaceInfoFinderUtil";

let client: LanguageClient;
let _context: vscode.ExtensionContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { URL } from 'url';
import * as path from 'path';
import * as fs from 'fs';
import { glob } from 'glob';
import { sendTelemetryEvent} from "../client/power-pages/telemetry";
import { ITelemetry } from "../client/telemetry/ITelemetry";

const portalConfigFolderName = '.portalconfig';

Expand Down Expand Up @@ -72,30 +70,3 @@ function isSibling(file: string): URL | null {
}
return null;
}

export function getPortalsOrgURLs(workspaceRootFolders:WorkspaceFolder[] | null, telemetry: ITelemetry ) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let output: any[] = [];
try {
workspaceRootFolders?.forEach(workspaceRootFolder => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const manifestFiles = glob.sync('**/*-manifest.yml', { dot: true, cwd: workspaceRootFolder!.uri });
if (manifestFiles.length == 0) {
output = [{
orgURL: '',
isManifestExists: false
}];
}else {
manifestFiles?.forEach(manifestFile =>{
output.push({
orgURL: manifestFile.split("-manifest")[0].replace(/.*[portalconfig]\//,''),
isManifestExists: true
});
})
}
});
}catch(exception){
sendTelemetryEvent(telemetry, { methodName:getPortalsOrgURLs.name,eventName: 'getPortalsOrgURLs', exception: exception as Error });
}
return output;
}
38 changes: 38 additions & 0 deletions src/common/utilities/WorkspaceInfoFinderUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import {
WorkspaceFolder
} from 'vscode-languageserver/node';
import { glob } from 'glob';
import { sendTelemetryEvent } from "../../client/power-pages/telemetry";
import { ITelemetry } from "../../client/telemetry/ITelemetry";

export function getPortalsOrgURLs(workspaceRootFolders: WorkspaceFolder[] | null, telemetry: ITelemetry) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let output: any[] = [];
try {
workspaceRootFolders?.forEach(workspaceRootFolder => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const manifestFiles = glob.sync('**/*-manifest.yml', { dot: true, cwd: workspaceRootFolder!.uri });
if (manifestFiles.length == 0) {
output = [{
orgURL: '',
isManifestExists: false
}];
} else {
manifestFiles?.forEach(manifestFile => {
output.push({
orgURL: manifestFile.split("-manifest")[0].replace(/.*[portalconfig]\//, ''),
isManifestExists: true
});
})
}
});
} catch (exception) {
sendTelemetryEvent(telemetry, { methodName: getPortalsOrgURLs.name, eventName: 'getPortalsOrgURLs', exception: exception as Error });
}
return output;
}
5 changes: 3 additions & 2 deletions src/server/YamlServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let hasDiagnosticRelatedInformationCapability = false;


connection.onInitialize((params: InitializeParams) => {

const capabilities = params.capabilities;
workspaceRootFolders = params.workspaceFolders;
// Does the client support the `workspace/configuration` request?
Expand Down Expand Up @@ -93,7 +94,7 @@ connection.onInitialized(() => {
// The content of a text document has changed. This event is emitted
// when the text document first opened or when its content has changed.
documents.onDidChangeContent(change => {
editedTextDocument = (change.document);
editedTextDocument = (change.document);
});


Expand Down Expand Up @@ -135,7 +136,7 @@ function getSuggestions(rowIndex: number, pathOfFileBeingEdited: string) {
}
}
// we send telemetry data only in case of success, otherwise the logs will be bloated with unnecessary data
if(completionItems.length > 0) {
if (completionItems.length > 0) {
telemetryData.properties.success = 'true';
telemetryData.measurements.countOfAutoCompleteResults = completionItems.length;
sendTelemetryEvent(connection, telemetryData);
Expand Down
4 changes: 2 additions & 2 deletions src/server/lib/PortalManifestReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { URL } from 'url';
import * as path from 'path';
import * as fs from 'fs';
import * as YAML from 'yaml';
import { getPortalConfigFolderUrl } from '../../common/PortalConfigFinder';
import { getPortalConfigFolderUrl } from '../../common/utilities/PathFinderUtil';

const manifest = '-manifest';

Expand All @@ -19,7 +19,7 @@ export interface IManifestElement {
RecordId: string;
}

export function getMatchedManifestRecords(workspaceRootFolders : WorkspaceFolder[] | null, keyForCompletion: string, pathOfFileBeingEdited?: string) : IManifestElement[] {
export function getMatchedManifestRecords(workspaceRootFolders: WorkspaceFolder[] | null, keyForCompletion: string, pathOfFileBeingEdited?: string): IManifestElement[] {
let matchedManifestRecords: IManifestElement[] = [];
if (pathOfFileBeingEdited) {
const portalConfigFolderUrl = getPortalConfigFolderUrl(workspaceRootFolders, pathOfFileBeingEdited) as URL | null; //https://github.com/Microsoft/TypeScript/issues/11498
Expand Down

0 comments on commit 090bdf7

Please sign in to comment.