-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GSC side panel with "Workspace", "File" and "Other" views. It s…
…hows information about workspace setup, parsed GSC files and available commands to run.
- Loading branch information
Showing
9 changed files
with
490 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as vscode from 'vscode'; | ||
import { LoggerOutput } from './LoggerOutput'; | ||
import { GscWorkspaceTreeDataProvider } from './GscSidePanelWorkspaceTreeDataProvider'; | ||
import { GscFileTreeDataProvider } from './GscSidePanelFileTreeDataProvider'; | ||
import { OtherViewProvider } from './GscSidePanelOtherViewProvider'; | ||
|
||
export class GscSidePanel { | ||
public static fileInfoProvider: GscFileTreeDataProvider; | ||
public static workspaceInfoProvider: GscWorkspaceTreeDataProvider; | ||
public static otherViewProvider: OtherViewProvider; | ||
|
||
// Activates the logger and registers the necessary disposal function | ||
static async activate(context: vscode.ExtensionContext) { | ||
LoggerOutput.log("[GscSidePanel] Activating"); | ||
|
||
this.fileInfoProvider = new GscFileTreeDataProvider(); | ||
context.subscriptions.push(vscode.window.registerTreeDataProvider("gsc-view-file-info", GscSidePanel.fileInfoProvider)); | ||
|
||
this.workspaceInfoProvider = new GscWorkspaceTreeDataProvider(); | ||
context.subscriptions.push(vscode.window.registerTreeDataProvider("gsc-view-workspace-info", GscSidePanel.workspaceInfoProvider)); | ||
|
||
this.otherViewProvider = new OtherViewProvider(); | ||
context.subscriptions.push(vscode.window.registerWebviewViewProvider("gsc-view-other", GscSidePanel.otherViewProvider)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import * as vscode from 'vscode'; | ||
import { GscFiles } from './GscFiles'; | ||
|
||
|
||
interface GscTreeItemData { | ||
label: string; | ||
originalLabel?: string; | ||
children?: GscTreeItemData[]; | ||
command?: vscode.Command; | ||
|
||
icon?: vscode.ThemeIcon; | ||
} | ||
|
||
enum GscTreeItem { | ||
ReferenceableGameRootFolders = 'Referenceable Game Root Folders', | ||
IgnoredFilePaths = 'Ignored File Paths', | ||
IgnoredFunctionNames = 'Ignored Function Names', | ||
CurrentGame = 'Current Game', | ||
ErrorDiagnostics = 'Error Diagnostics' | ||
} | ||
|
||
|
||
export class GscFileTreeDataProvider implements vscode.TreeDataProvider<GscTreeItemData> { | ||
private _onDidChangeTreeData: vscode.EventEmitter<GscTreeItemData | undefined | void> = new vscode.EventEmitter<GscTreeItemData | undefined | void>(); | ||
readonly onDidChangeTreeData: vscode.Event<GscTreeItemData | undefined | void> = this._onDidChangeTreeData.event; | ||
|
||
constructor() { | ||
} | ||
|
||
getTreeItem(element: GscTreeItemData): vscode.TreeItem { | ||
const treeItem = new vscode.TreeItem( | ||
element.label, | ||
element.children ? this.getCollapsibleState(element.originalLabel || element.label) : vscode.TreeItemCollapsibleState.None | ||
); | ||
|
||
return treeItem; | ||
} | ||
|
||
getChildren(element?: GscTreeItemData): GscTreeItemData[] { | ||
|
||
// Its a root element | ||
if (!element) { | ||
|
||
const editor = vscode.window.activeTextEditor; | ||
const gscFile = editor ? GscFiles.getCachedFile(editor.document.uri) : undefined; | ||
|
||
if (editor && gscFile) { | ||
|
||
const referenceableGameRootFolders = gscFile.config.referenceableGameRootFolders.map((folder: any) => ({ label: vscode.workspace.asRelativePath(folder.uri, true) })); | ||
const ignoredFilePaths = gscFile.config.ignoredFilePaths.map((path: string) => ({ label: path })); | ||
const ignoredFunctionNames = gscFile.config.ignoredFunctionNames.map((name: string) => ({ label: name })); | ||
const currentGame = [{ label: gscFile.config.currentGame }]; | ||
const errorDiagnostics = [{ label: gscFile.config.errorDiagnostics }]; | ||
|
||
return [ | ||
{ label: `${GscTreeItem.ReferenceableGameRootFolders} (${referenceableGameRootFolders.length})`, originalLabel: GscTreeItem.ReferenceableGameRootFolders, children: referenceableGameRootFolders }, | ||
{ label: `${GscTreeItem.IgnoredFilePaths} (${ignoredFilePaths.length})`, originalLabel: GscTreeItem.IgnoredFilePaths, children: ignoredFilePaths }, | ||
{ label: `${GscTreeItem.IgnoredFunctionNames} (${ignoredFunctionNames.length})`, originalLabel: GscTreeItem.IgnoredFunctionNames, children: ignoredFunctionNames }, | ||
{ label: `${GscTreeItem.CurrentGame} (${currentGame.length})`, originalLabel: GscTreeItem.CurrentGame, children: currentGame }, | ||
{ label: `${GscTreeItem.ErrorDiagnostics} (${errorDiagnostics.length})`, originalLabel: GscTreeItem.ErrorDiagnostics, children: errorDiagnostics } | ||
]; | ||
} | ||
|
||
return [ | ||
{ label: 'No active editor' } | ||
]; | ||
} | ||
return element.children || []; | ||
} | ||
|
||
refresh(): void { | ||
this._onDidChangeTreeData.fire(); | ||
} | ||
|
||
private getCollapsibleState(label: string): vscode.TreeItemCollapsibleState { | ||
switch (label) { | ||
case GscTreeItem.ReferenceableGameRootFolders: | ||
case GscTreeItem.IgnoredFilePaths: | ||
case GscTreeItem.IgnoredFunctionNames: | ||
return vscode.TreeItemCollapsibleState.Expanded; | ||
default: | ||
return vscode.TreeItemCollapsibleState.Collapsed; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import * as vscode from 'vscode'; | ||
import { GscFiles } from './GscFiles'; | ||
import { GscDiagnosticsCollection } from './GscDiagnosticsCollection'; | ||
import { Issues } from './Issues'; | ||
import { Updates } from './Updates'; | ||
|
||
|
||
export class OtherViewProvider implements vscode.WebviewViewProvider { | ||
|
||
private _view?: vscode.WebviewView; | ||
|
||
constructor() { | ||
this.updateWebviewContent(); | ||
} | ||
|
||
resolveWebviewView(webviewView: vscode.WebviewView) { | ||
this._view = webviewView; | ||
webviewView.webview.options = { enableScripts: true }; | ||
webviewView.webview.html = this.getHtmlContent(); | ||
|
||
webviewView.webview.onDidReceiveMessage(message => { | ||
switch (message.command) { | ||
case 'parseAllFiles': | ||
void GscFiles.parseAllFiles(); | ||
break; | ||
case 'reDiagnoseAllFiles': | ||
void GscDiagnosticsCollection.updateDiagnosticsForAll("sidePanel"); | ||
break; | ||
case 'reportIssue': | ||
Issues.showIssueWindow(false); | ||
break; | ||
case 'showExtensionUpdates': | ||
Updates.showUpdateWindow(); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
// Update the webview content based on the current active editor | ||
public updateWebviewContent() { | ||
if (!this._view) { | ||
return; | ||
} | ||
this._view.webview.html = this.getHtmlContent(); | ||
|
||
} | ||
|
||
private getHtmlContent(): string { | ||
return `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<style> | ||
button { | ||
background-color: var(--vscode-button-background); | ||
color: var(--vscode-button-foreground); | ||
border: 1px solid var(--vscode-button-border, transparent); | ||
border-radius: 2px; | ||
padding: 4px; | ||
cursor: pointer; | ||
margin: 4px; | ||
text-align: center; | ||
line-height: 18px; | ||
text-decoration: none; | ||
width: 100%; | ||
} | ||
button:hover { | ||
background-color: var(--vscode-button-hoverBackground); | ||
} | ||
p { | ||
margin-bottom: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>GSC Files:</p> | ||
<button id="button1" class="codicon codicon-file">Parse all files</button><br> | ||
<button id="button2">Re-diagnose all files</button><br> | ||
<p>Issues:</p> | ||
<button id="button3">Report an issue</button><br> | ||
<p>Updates:</p> | ||
<button id="button4">Show extension updates</button><br> | ||
<script> | ||
const vscode = acquireVsCodeApi(); | ||
document.getElementById('button1').addEventListener('click', () => { | ||
vscode.postMessage({ command: 'parseAllFiles' }); | ||
}); | ||
document.getElementById('button2').addEventListener('click', () => { | ||
vscode.postMessage({ command: 'reDiagnoseAllFiles' }); | ||
}); | ||
document.getElementById('button3').addEventListener('click', () => { | ||
vscode.postMessage({ command: 'reportIssue' }); | ||
}); | ||
document.getElementById('button4').addEventListener('click', () => { | ||
vscode.postMessage({ command: 'showExtensionUpdates' }); | ||
}); | ||
</script> | ||
</body> | ||
</html>`; | ||
} | ||
|
||
} |
Oops, something went wrong.