Skip to content

Commit ad9883f

Browse files
committed
0.3.6
1 parent 52986b0 commit ad9883f

File tree

11 files changed

+290
-95
lines changed

11 files changed

+290
-95
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Install from vscode marketplace [SharedLock](https://marketplace.visualstudio.co
1717
![Demo](./resources/images/demo.gif)
1818

1919

20+
## Screens
21+
22+
![Release](./resources/images/sharedlock_exp.gif)
23+
24+
![Release](./resources/images/release.gif)
25+
26+
![Release](./resources/images/folderlock.gif)
27+
2028
## How it works
2129

2230
For preventing merge confilicts while editing same file, developer can lock the file, so other team members

package-lock.json

Lines changed: 22 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sharedlock",
33
"displayName": "SharedLock",
44
"description": "Sharing file locks in workspace files via network",
5-
"version": "0.3.2",
5+
"version": "0.3.6",
66
"publisher": "code4bones",
77
"icon": "resources/icons/logo.png",
88
"repository": {
@@ -36,12 +36,12 @@
3636
"menus": {
3737
"editor/title/context": [
3838
{
39-
"when": "sharedlock.state == 'locked' && sharedlock.isOwner",
39+
"when": "sharedlock.state == 'locked' && sharedlock.isOwner && sharedlock.hasGit",
4040
"command": "sharedlock.unlock",
4141
"group": "sharedlock"
4242
},
4343
{
44-
"when": "sharedlock.state != 'locked'",
44+
"when": "sharedlock.state != 'locked' && sharedlock.hasGit",
4545
"command": "sharedlock.lock",
4646
"group": "sharedlock"
4747
}
@@ -50,19 +50,19 @@
5050
{
5151
"command": "sharedlock.wipeLocked",
5252
"group": "navigation@0",
53-
"when": "view == sharedlock.locksView"
53+
"when": "view == sharedlock.locksView && sharedlock.hasGit"
5454
}
5555
],
5656
"explorer/context": [
5757
{
5858
"command": "sharedlock.lockFolder",
59-
"group": "navigation@0",
60-
"when": "explorerResourceIsFolder"
59+
"group": "1_modification",
60+
"when": "explorerResourceIsFolder && sharedlock.hasGit"
6161
}
6262
],
6363
"view/item/context": [
6464
{
65-
"when": "viewItem == owned",
65+
"when": "viewItem == owned && sharedlock.hasGit",
6666
"command": "sharedlock.ctxUnlock",
6767
"group": "sharedlock"
6868
}
@@ -71,8 +71,7 @@
7171
"commands": [
7272
{
7373
"command": "sharedlock.lockFolder",
74-
"title": "Lock Folder Contents",
75-
"category": ""
74+
"title": "Lock Folder Contents"
7675
},
7776
{
7877
"command": "sharedlock.toggleLock",
@@ -109,7 +108,8 @@
109108
{
110109
"id": "sharedlock.locksView",
111110
"name": "SharedLocks",
112-
"type": "tree"
111+
"type": "tree",
112+
"when": "sharedlock.hasGit"
113113
}
114114
]
115115
},
@@ -194,6 +194,7 @@
194194
"devDependencies": {
195195
"@eslint/js": "^9.13.0",
196196
"@stylistic/eslint-plugin": "^2.9.0",
197+
"@types/micromatch": "^4.0.9",
197198
"@types/node": "^20",
198199
"@types/vscode": "^1.73.0",
199200
"esbuild": "^0.24.0",
@@ -209,6 +210,7 @@
209210
"dependencies": {
210211
"glob": "^11.0.0",
211212
"ioredis": "^5.4.1",
213+
"micromatch": "^4.0.8",
212214
"vscode-ext-codicons": "^1.6.0"
213215
}
214216
}

resources/images/folderlock.png

94.9 KB
Loading

resources/images/release.png

239 KB
Loading
31.5 KB
Loading

src/commands.ts

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { LockMessage } from "./types";
55
import * as path from "path";
66
import * as fs from "fs";
77
import {glob} from "glob";
8+
import * as mm from "micromatch";
89

910
export function registerCommands(ctx:vscode.ExtensionContext) {
1011
const ctrl = new Controller(ctx);
1112
ctx.subscriptions.push(ctrl);
1213

13-
function indicatorAction () {
14+
function toggleLock () {
1415
ctrl.toggleLock();
1516
}
1617

@@ -32,63 +33,62 @@ export function registerCommands(ctx:vscode.ExtensionContext) {
3233

3334
function ctxOpen(msg:LockMessage) {
3435
vscode.workspace.workspaceFolders?.forEach((ws)=>{
35-
const [,fileName] = msg.file.split(":");
36-
const file = path.join(ws.uri.fsPath,fileName);
37-
console.log("Try open",file);
38-
if ( fs.existsSync(file) ) {
39-
vscode.window.showTextDocument(vscode.Uri.parse(file));
40-
return;
41-
}
36+
const [ns,fileName] = msg.file.split(":");
37+
const mask = path.join(ws.uri.path,'**',ns,"**",fileName);
38+
glob(mask)
39+
.then((files)=>{
40+
if ( files?.length ) {
41+
const [file] = files;
42+
vscode.window.showTextDocument(vscode.Uri.parse(file));
43+
} else {
44+
vscode.window.showErrorMessage(`Cannot open document,using ${mask}`);
45+
}
46+
});
4247
});
4348
}
4449

4550
function ctxLockFolder (startDir:vscode.Uri) {
46-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
47-
const lockTree = (uri:vscode.Uri,ign?:string[]) => {
48-
vscode.workspace.fs.readDirectory(uri)
49-
.then((dirs)=>{
50-
dirs.forEach(([file,type])=>{
51-
const lock = vscode.Uri.parse(path.join(uri.path,file));
52-
if ( type === vscode.FileType.Directory ) {
53-
if ( ign ) {
54-
lockTree(lock,ign);
55-
}
56-
} else {
57-
console.log("Loking",lock.path);
58-
}
59-
});
60-
});
61-
};
6251

6352
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6453
const getFiles = (ignore:string[]) => {
65-
glob(path.join(startDir.path,'**/*'),{ignore,dot:true})
54+
return glob(path.join(startDir.path,'**/*'),{ignore,dot:true})
6655
.then((files)=>{
67-
console.log("Files",files);
56+
return mm(files,"**/*.*",{ignore});
6857
});
6958
};
7059

60+
const getIgnores = async () => {
61+
const root = vscode.workspace.getWorkspaceFolder(startDir);
62+
const mask = path.join(root!.uri.path,"**",".gitignore");
63+
return glob(mask)
64+
.then((files)=>{
65+
return files.map((gitIgnore)=>{
66+
const content = fs.readFileSync(gitIgnore).toString("utf8");
67+
return content.split("\n").map((line) => line.trim())
68+
.filter(line => line.length > 0 && !line.startsWith("#"));
69+
});
70+
}).then((igns)=>{
71+
const uniq = new Set();
72+
igns.forEach((file) => file.map(f => uniq.add( `*/**/${f}`)));
73+
return Array.from(uniq.keys()) as string[];
74+
});
75+
};
7176

72-
const root = vscode.workspace.getWorkspaceFolder(startDir);
73-
const gitIgnore = path.join(root!.uri.path,".gitignore");
74-
if ( fs.existsSync(gitIgnore) ) {
75-
const content = fs.readFileSync(gitIgnore).toString("utf8");
76-
const ignores = content.split("\n").map((line) => line.trim()).filter(line => line.length > 0 && !line.startsWith("#"));
77-
console.log("IGN",ignores.map((f) => path.join("**",f)));
78-
// getFiles(ignores);
79-
// lockTree(startDir,ignores);
80-
} else {
81-
vscode.window.showInformationMessage("Where are no .gitignore file, only upper level will be processed...");
82-
// lockTree(startDir);
83-
}
84-
// console.log("FILE",gitIgnore);
85-
// lockTree(startDir);
86-
// vscode.Uri.parse(path.join(uri.path,file)
87-
//lockTree(startDir);
77+
getIgnores()
78+
.then((ignores)=>{
79+
console.log("IGNO",ignores);
80+
getFiles(ignores)
81+
.then((locks)=>{
82+
ctrl.storage.lockGroup(locks);
83+
});
84+
});
8885
}
8986

9087

91-
ctx.subscriptions.push(vscode.commands.registerCommand(C.statusBarAction,indicatorAction));
88+
/*
89+
Status bar toggler
90+
*/
91+
ctx.subscriptions.push(vscode.commands.registerCommand(C.statusBarAction,toggleLock));
9292

9393
/*
9494
Reflects other side locks
@@ -102,9 +102,13 @@ export function registerCommands(ctx:vscode.ExtensionContext) {
102102
ctx.subscriptions.push(vscode.commands.registerCommand(C.LockCommands.unlock,() => updateLock(C.LockState.Unlocked)));
103103
ctx.subscriptions.push(vscode.commands.registerCommand(C.LockCommands.wipeLocked,() => wipeLocked()));
104104
ctx.subscriptions.push(vscode.commands.registerCommand(C.LockCommands.ctxUnlock,(args) => ctxUnlock(args)));
105-
ctx.subscriptions.push(vscode.commands.registerCommand(C.LockCommands.ctxOpen,(args) => ctxOpen(args)));
106105
ctx.subscriptions.push(vscode.commands.registerCommand(C.LockCommands.lockFolder,(args) => ctxLockFolder(args)));
107106

107+
/*
108+
Open doc from expoloer
109+
*/
110+
ctx.subscriptions.push(vscode.commands.registerCommand(C.LockCommands.ctxOpen,(args) => ctxOpen(args)));
111+
108112

109113
return ctrl;
110114
}

src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { LocksView } from './locksView';
44
import { createLogger } from './logger';
55

66
export function activate(context: vscode.ExtensionContext) {
7+
8+
const folders:string[] = [];
9+
vscode.workspace.workspaceFolders?.forEach((ws)=>{
10+
folders.push(ws.uri.path);
11+
});
12+
context.globalState.update("roots",JSON.stringify(folders));
713
createLogger(context).appendLine("Starting...");
814
const ctrl = registerCommands(context);
915
new LocksView(context,ctrl);

0 commit comments

Comments
 (0)