Skip to content

Commit

Permalink
Merge pull request #2042 from julesyan/refreshFile
Browse files Browse the repository at this point in the history
Refresh file
  • Loading branch information
chrjorgensen authored May 28, 2024
2 parents 0d6b9c6 + cec100f commit 1b03759
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ Thanks so much to everyone [who has contributed](https://github.com/codefori/vsc
* [@ThePrez](https://github.com/ThePrez)
* [@BoykaZhu](https://github.com/BoykaZhu)
* [@krka01](https://github.com/krka01)
* [@william-xiang](https://github.com/william-xiang)
* [@william-xiang](https://github.com/william-xiang)
* [@julesyan](https://github.com/julesyan)
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,12 @@
"icon": "$(settings-gear)",
"enablement": "!code-for-ibmi:debugWorking"
},
{
"command": "code-for-ibmi.refreshFile",
"title": "Refresh File",
"category": "IBM i",
"icon": "$(refresh)"
},
{
"command": "code-for-ibmi.searchObjectBrowser",
"title": "Highlight",
Expand Down Expand Up @@ -2366,6 +2372,11 @@
"command": "code-for-ibmi.clearDiagnostics",
"when": "code-for-ibmi:connected",
"group": "navigation@3"
},
{
"command": "code-for-ibmi.refreshFile",
"when": "code-for-ibmi:connected && (resourceScheme == streamfile || resourceScheme == member)",
"group": "navigation@4"
}
],
"view/item/context": [
Expand Down
7 changes: 6 additions & 1 deletion src/api/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,14 @@ export namespace Tools {
* Without this, it's possible for the same document to be opened twice simply due to the readonly flag.
*/
export function findExistingDocumentUri(uri: vscode.Uri) {
const possibleDoc = findExistingDocument(uri);
return possibleDoc?.uri || uri;
}

export function findExistingDocument(uri: vscode.Uri) {
const baseUriString = uriStringWithoutFragment(uri);
const possibleDoc = vscode.workspace.textDocuments.find(document => uriStringWithoutFragment(document.uri) === baseUriString);
return possibleDoc?.uri || uri;
return possibleDoc;
}

/**
Expand Down
28 changes: 27 additions & 1 deletion src/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Action, BrowserItem, DeploymentMethod, MemberItem, OpenEditableOptions,
import { SearchView } from "./views/searchView";
import { ActionsUI } from './webviews/actions';
import { VariablesUI } from "./webviews/variables";
import { t } from './locale';

export let instance: Instance;

Expand Down Expand Up @@ -700,7 +701,32 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
vscode.commands.executeCommand(`code-for-ibmi.openEditable`, item.path, { readonly });
}),
vscode.commands.registerCommand("code-for-ibmi.updateConnectedBar", updateConnectedBar),
);

vscode.commands.registerCommand("code-for-ibmi.refreshFile", async (uri?: vscode.Uri) => {
let doc: vscode.TextDocument | undefined;
if (uri) {
doc = Tools.findExistingDocument(uri);
} else {
const editor = vscode.window.activeTextEditor;
doc = editor?.document;
}

if (doc?.isDirty) {
vscode.window
.showWarningMessage(
t(`discard.changes`),
{ modal: true },
t(`Continue`))
.then(result => {
if (result === t(`Continue`)) {
vscode.commands.executeCommand(`workbench.action.files.revert`);
}
});
} else {
vscode.commands.executeCommand(`workbench.action.files.revert`);
}
}),
);

ActionsUI.initialize(context);
VariablesUI.initialize(context);
Expand Down
1 change: 1 addition & 0 deletions src/locale/ids/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"delete": "Slet",
"detail.reading.error": "Fejl ved læsning af debug service detail fil {0}: {1}",
"directory": "mappe",
"discard.changes": "Dine ændringer vil blive kasseret",
"download.certificate": "Hent certifikat",
"duplicate": "Kopier",
"enddbgsvr.failed": "Fejl ved stop af debug server: {0}",
Expand Down
1 change: 1 addition & 0 deletions src/locale/ids/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"delete": "Delete",
"detail.reading.error": "Failed to read debug service detail file {0}: {1}",
"directory": "directory",
"discard.changes": "Your changes will be discarded",
"download.certificate": "Download certificate",
"duplicate": "Duplicate",
"enddbgsvr.failed": "Failed to stop debug server: {0}",
Expand Down
1 change: 1 addition & 0 deletions src/locale/ids/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"delete": "Supprimer",
"detail.reading.error": "Erreur de lecture du fichier détail du service de débogage {0}: {1}",
"directory": "Répertoire",
"discard.changes": "Vos modifications vont être perdues",
"download.certificate": "Télécharger le certificat",
"duplicate": "Dupliquer",
"enddbgsvr.failed": "Échec de l\"arrêt du serveur de débogage: {0}",
Expand Down

0 comments on commit 1b03759

Please sign in to comment.