-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
12 hover provider for manifest files (#26)
* updated globalState and refactored * fixed undefined of repoData * added scan for manifest when user creates a new file
- Loading branch information
1 parent
a218abe
commit a5cc26a
Showing
14 changed files
with
160 additions
and
116 deletions.
There are no files selected for viewing
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
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,92 @@ | ||
import * as vscode from "vscode"; | ||
import * as path from "path"; | ||
import { MessageStatus, Organization, DebrickedCommands } from "../constants"; | ||
import { ScanService, FileService } from "services"; | ||
import { Common, ErrorHandler, Logger, StatusMessage, StatusBarMessageHelper, GlobalState } from "../helpers"; | ||
|
||
export class ManifestWatcher { | ||
private static instance: ManifestWatcher; | ||
private globalWatcher: vscode.FileSystemWatcher | null = null; | ||
private manifestWatchers: vscode.FileSystemWatcher[] = []; | ||
|
||
private constructor() {} | ||
private static get globalState(): GlobalState { | ||
return GlobalState.getInstance(); | ||
} | ||
|
||
public static getInstance(): ManifestWatcher { | ||
if (!ManifestWatcher.instance) { | ||
ManifestWatcher.instance = new ManifestWatcher(); | ||
} | ||
return ManifestWatcher.instance; | ||
} | ||
|
||
public async setupWatchers(context: vscode.ExtensionContext): Promise<void> { | ||
try { | ||
Logger.logMessageByStatus(MessageStatus.INFO, "Setting up Manifest File Watchers"); | ||
ManifestWatcher.globalState.setGlobalData(Organization.seqIdKey, Common.generateHashCode()); | ||
|
||
// Setup global watcher if not already set | ||
if (!this.globalWatcher) { | ||
this.setupGlobalWatcher(context); | ||
} | ||
|
||
const filesToScan = (await FileService.findFilesService()) || []; | ||
await this.updateManifestWatchers(filesToScan, context); | ||
|
||
StatusBarMessageHelper.setStatusBarMessage( | ||
StatusMessage.getStatusMessage(MessageStatus.COMPLETE, DebrickedCommands.SCAN.cli_command), | ||
); | ||
} catch (error: any) { | ||
ErrorHandler.handleError(error); | ||
} finally { | ||
StatusBarMessageHelper.setStatusBarMessage( | ||
StatusMessage.getStatusMessage(MessageStatus.FINISHED, DebrickedCommands.SCAN.cli_command), | ||
); | ||
Logger.logMessageByStatus(MessageStatus.INFO, "Watchers for Manifest files are now ready to scan."); | ||
} | ||
} | ||
|
||
private setupGlobalWatcher(context: vscode.ExtensionContext): void { | ||
this.globalWatcher = vscode.workspace.createFileSystemWatcher("**/*"); | ||
this.globalWatcher.onDidCreate(async () => { | ||
await this.setupWatchers(context); | ||
}); | ||
context.subscriptions.push(this.globalWatcher); | ||
} | ||
|
||
private async updateManifestWatchers(filesToScan: string[], context: vscode.ExtensionContext): Promise<void> { | ||
// Dispose old watchers | ||
this.manifestWatchers.forEach((watcher) => watcher.dispose()); | ||
this.manifestWatchers = []; | ||
|
||
if (filesToScan.length > 0) { | ||
const filesPattern = new RegExp(filesToScan.map((file) => `^${file}$`).join("|")); | ||
|
||
vscode.window.onDidChangeActiveTextEditor((editor) => { | ||
if (editor && filesPattern.test(path.basename(editor.document.fileName))) { | ||
vscode.commands.executeCommand("setContext", "debrickedFilesToScan", true); | ||
} else { | ||
vscode.commands.executeCommand("setContext", "debrickedFilesToScan", false); | ||
} | ||
}); | ||
|
||
filesToScan.forEach((file: string) => { | ||
const watcher = vscode.workspace.createFileSystemWatcher(`**/${file}`); | ||
const runScan = async () => { | ||
await ScanService.scanService(); | ||
}; | ||
|
||
watcher.onDidChange(runScan); | ||
watcher.onDidCreate(runScan); | ||
watcher.onDidDelete(runScan); | ||
Logger.logMessageByStatus(MessageStatus.INFO, `Register watcher on ${file}`); | ||
context.subscriptions.push(watcher); | ||
this.manifestWatchers.push(watcher); | ||
}); | ||
Logger.logInfo("Watchers added successfully"); | ||
} else { | ||
Logger.logInfo("No manifest files found"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.