Closed adhamu closed 4 years ago
Hello, yes this is currently the expected behaviour (also similar to what described in #2)
I'm not sure if that features is supported by the Sublime Text / Sublime Merge integration either, but I had it working this way for two reasons:
.git
folder is present in the root of the project / workspace (as opposed to being activated for every instance of the editor regardless)Because workspaces seems to be designed to address the exact scenario you describe I'd feel that's a valid solution (I implemented supports for workspaces even though I don't usually use them myself) but please let me know if you have other suggestions.
I'm not sure. I've been looking at the Predefined Variables and not sure if some of these might be more suitable (I've not looked in detail at what the extension is currently using).
Personally, I use this extension mainly for "open this file in Sublime Merge" and "view line history" if that helps
FWIW, I had the same directory structure in Sublime Text which seemed to work
Here's a quick example I've knocked together using Sindre Sorhus's findUp library.
import * as vscode from 'vscode';
import * as child from 'child_process';
import * as findUp from 'find-up';
import * as path from 'path';
const viewFileHistory = async () => {
if (vscode.window.activeTextEditor) {
let filePath = vscode.window.activeTextEditor.document.uri.path;
const findRepo = await findUp('.git', {
cwd: path.dirname(filePath),
type: 'directory',
});
if (!findRepo) {
return;
}
const repoLocation = path.dirname(findRepo);
filePath = filePath.replace(`${repoLocation}/`, '');
child.execFile(`smerge`, ['search', `file:"${filePath}"`], {
cwd: repoLocation,
});
}
};
export function activate(context: vscode.ExtensionContext) {
const viewFileHistoryCommand = vscode.commands.registerCommand(
'history-in-sublime-merge.viewFileHistory',
viewFileHistory
);
context.subscriptions.push(viewFileHistoryCommand);
}
Thanks @adhamu
In you're example you are adding the command based on whether a ".git" folder is found as a parent of the current file, however if I remember correctly that subscription is not file specific and set up only once when the extension is activated, right?
Anyway then the main issue would be that I'm using the workspaceContains
activation event (https://code.visualstudio.com/api/references/activation-events) to tell vscode when to activate the extension (i.e. only when the workspace contains the .git
folder) although I just noticed it should be possible to do something like "workspaceContains:**/.git"
(see https://github.com/giovdk21/vscode-sublime-merge/blob/master/package.json#L34)
Anyway I'll give it a go trying what I described above and the info you provided! Thanks.
p.s. can't promise I will be able to try this anytime soon but hopefully at some point in June!
No worries. I’ll keep an eye out and in the meantime, I’ll have a play with some extension development
I've had a play and published my own extension for my use-case. I'll close this issue
https://marketplace.visualstudio.com/items?itemName=adhamu.history-in-sublime-merge
My current setup is that I have a top-level
code
directory where all of my projects (git respositories) live.Eg.
I add the
code
folder to my VSCode workspace but upon clicking "File history in Sublime Merge" for example, nothing happens.It seems that I have to add each project to my VSCode workspace individually so that my structure is like so:
Is there any way this extension can detect if it's inside a top-level directory and open the appropriate repository?