-
Hi,
What classes do I need to override and change to do the above? Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
safisa
Oct 28, 2024
Replies: 2 comments 1 reply
-
I have resolved it by overriding the DiffService class:
@injectable()
export class CustomDiffService extends DiffService {
@inject(PreferenceService)
protected readonly preferenceService: PreferenceService;
public async openDiffEditor(left: URI, right: URI, label?: string, options?: OpenerOptions): Promise<void> {
//super.openDiffEditor(left, right, label, options);
if (left.scheme === 'file' && right.scheme === 'file') {
const [resolvedLeft, resolvedRight] = await this.fileService.resolveAll([{ resource: left }, { resource: right }]);
if (resolvedLeft.success && resolvedRight.success) {
const leftStat = resolvedLeft.stat;
const rightStat = resolvedRight.stat;
if (leftStat && rightStat) {
if (!leftStat.isDirectory && !rightStat.isDirectory) {
const uri = DiffUris.encode(left, right, label);
// my code
const opened = await this.openTextEditorDiff(left, right, uri, options);
if (opened) {
return;
}
//
await open(this.openerService, uri, options);
} else {
const details = (() => {
if (leftStat.isDirectory && rightStat.isDirectory) {
return 'Both resource were a directory.';
} else {
if (leftStat.isDirectory) {
return `'${left.path.base}' was a directory.`;
} else {
return `'${right.path.base}' was a directory.`;
}
}
});
this.messageService.warn(`Directories cannot be compared. ${details()}`);
}
}
}
} else {
const uri = DiffUris.encode(left, right, label);
// my code
const opened = await this.openTextEditorDiff(left, right, uri, options);
if (opened) {
return;
}
//
await open(this.openerService, uri, options);
}
}
private async openTextEditorDiff(left: URI, right: URI, uri: URI, options?: OpenerOptions) {
let useTextEditor = this.preferenceService.get<boolean>("compareFiles.alwaysUseTextEditor");
let arrExtensionsForTextEditor = this.preferenceService.get<string[]>("compareFiles.useTextEditorForSpecificFileExtensions");
if (!useTextEditor) {
arrExtensionsForTextEditor?.forEach(ext => {
if (right.path?.base?.toLowerCase().endsWith(ext.toLowerCase())) {
useTextEditor = true;
}
});
}
let openers = await this.openerService.getOpeners(uri, options);
//let customEditorHandler = openers.find(h => h.id.includes("custom-editor"));
if (useTextEditor) {
const editorHandler = openers.find(h => h.id === "editor-preview-widget");
if (editorHandler && editorHandler.canHandle(uri, options)) {
await editorHandler.open(uri, options);
return true;
}
}
return false;
}
} @pisv Can you confirm that this is OK (especially the openTextEditorDiff method)? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
safisa
-
Yes, this is better. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have resolved it by overriding the DiffService class: