Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for delete cache error on windows #245

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vscode/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ export const OPEN_JDK_VERSION_DOWNLOAD_LINKS: { [key: string]: string } = {
"22": "https://download.java.net/java/GA/jdk22.0.1/c7ec1332f7bb44aeba2eb341ae18aca4/8/GPL/openjdk-22.0.1",
"21": "https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2"
};

export const NODE_WINDOWS_LABEL = "Windows_NT";
27 changes: 17 additions & 10 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { initializeRunConfiguration, runConfigurationProvider, runConfigurationN
import { InputStep, MultiStepInput } from './utils';
import { PropertiesView } from './propertiesView/propertiesView';
import { openJDKSelectionView } from './jdkDownloader';

import { NODE_WINDOWS_LABEL } from './constants';
const API_VERSION : string = "1.0";
const SERVER_NAME : string = "Oracle Java SE Language Server";
export const COMMAND_PREFIX : string = "jdk";
Expand All @@ -78,7 +78,7 @@ let nbProcess : ChildProcess | null = null;
let debugPort: number = -1;
let debugHash: string | undefined;
let consoleLog: boolean = !!process.env['ENABLE_CONSOLE_LOG'];

let deactivated:boolean = true;
export class NbLanguageClient extends LanguageClient {
private _treeViewService: TreeViewService;

Expand Down Expand Up @@ -327,8 +327,8 @@ class InitialPromise extends Promise<NbLanguageClient> {
}

export function activate(context: ExtensionContext): VSNetBeansAPI {
deactivated=false;
let log = vscode.window.createOutputChannel(SERVER_NAME);

var clientResolve : (x : NbLanguageClient) => void;
var clientReject : (err : any) => void;

Expand Down Expand Up @@ -510,19 +510,26 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {

context.subscriptions.push(vscode.commands.registerCommand(COMMAND_PREFIX + ".delete.cache", async () => {
const storagePath = context.storageUri?.fsPath;
if(!storagePath){
if (!storagePath) {
vscode.window.showErrorMessage('Cannot find workspace path');
return;
}

const userDir = path.join(storagePath, "userdir");
if (userDir && fs.existsSync(userDir)) {
const confirmation = await vscode.window.showInformationMessage('Are you sure you want to delete cache for this workspace?',
const confirmation = await vscode.window.showInformationMessage('Are you sure you want to delete cache for this workspace and reload the window ?',
'Yes', 'Cancel');
if (confirmation === 'Yes') {
await fs.promises.rmdir(userDir, {recursive : true});
const res = await vscode.window.showInformationMessage('Cache cleared successfully for this workspace', 'Reload window');
if (res === 'Reload window') {
await vscode.commands.executeCommand('workbench.action.reloadWindow');
try {
await stopClient(client);
deactivated = true;
await killNbProcess(false, log);
await fs.promises.rmdir(userDir, { recursive: true });
await vscode.window.showInformationMessage("Cache deleted successfully", 'Reload window');
} catch (err) {
await vscode.window.showErrorMessage('Error deleting the cache', 'Reload window');
} finally {
vscode.commands.executeCommand("workbench.action.reloadWindow");
}
}
} else {
Expand Down Expand Up @@ -953,7 +960,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
if (p == nbProcess && code != 0 && code) {
vscode.window.showWarningMessage(`${SERVER_NAME} exited with ` + code);
}
if (stdErr?.match(/Cannot find java/) || os.type() === "Windows_NT" ) {
if (stdErr?.match(/Cannot find java/) || (os.type() === NODE_WINDOWS_LABEL && !deactivated) ) {
vscode.window.showInformationMessage(
"No JDK found!",
"Download JDK and setup automatically"
Expand Down