vscode-find-me 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ // A launch configuration that compiles the extension and then opens it inside a new window
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ {
6
+ "version": "0.2.0",
7
+ "configurations": [
8
+ {
9
+ "name": "Run Extension",
10
+ "type": "extensionHost",
11
+ "request": "launch",
12
+ "runtimeExecutable": "${execPath}",
13
+ "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
14
+ "outFiles": ["${workspaceFolder}/out/**/*.js"],
15
+ "preLaunchTask": "npm: compile"
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,9 @@
1
+ // Place your settings in this file to overwrite default and user settings.
2
+ {
3
+ "files.exclude": {
4
+ "out": false // set this to true to hide the "out" folder with the compiled JS files
5
+ },
6
+ "search.exclude": {
7
+ "out": true // set this to false to include "out" folder in search results
8
+ }
9
+ }
@@ -0,0 +1,20 @@
1
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
2
+ // for the documentation about the tasks.json format
3
+ {
4
+ "version": "2.0.0",
5
+ "tasks": [
6
+ {
7
+ "type": "npm",
8
+ "script": "watch",
9
+ "problemMatcher": "$tsc-watch",
10
+ "isBackground": true,
11
+ "presentation": {
12
+ "reveal": "never"
13
+ },
14
+ "group": {
15
+ "kind": "build",
16
+ "isDefault": true
17
+ }
18
+ }
19
+ ]
20
+ }
package/.vscodeignore ADDED
@@ -0,0 +1,13 @@
1
+ .vscode/**
2
+ .vscode-test/**
3
+ node_modules/**
4
+ src/**
5
+ .gitignore
6
+ .yarnrc
7
+ webpack.config.js
8
+ vsc-extension-quickstart.md
9
+ **/tsconfig.json
10
+ **/eslint.config.mjs
11
+ **/*.map
12
+ **/*.ts
13
+ **/.vscode-test.*
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+
3
+ All notable changes to the "vscode-extension" extension will be documented in this file.
4
+
5
+ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6
+
7
+ ## [Unreleased]
8
+
9
+ - Initial release
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Find me - VS Code extension
2
+
3
+ This extension allows you to quickly find the file you're currently working on in your project.
4
+
5
+ Learn how to make plugins for VS Code
package/icon/logo.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "vscode-find-me",
3
+ "displayName": "Find Me",
4
+ "description": "Identify you current working folder in status bar",
5
+ "version": "0.0.1",
6
+ "engines": {
7
+ "vscode": "^1.97.0"
8
+ },
9
+ "icon": "icon/logo.png",
10
+ "publisher": "ganhu",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/Huuuuug/vscode-find-me.git"
14
+ },
15
+ "categories": [
16
+ "Other"
17
+ ],
18
+ "activationEvents": [
19
+ "*"
20
+ ],
21
+ "main": "./out/extension",
22
+ "contributes": {
23
+ "commands": [
24
+ {
25
+ "command": "fine-me.config",
26
+ "category": "Find Me",
27
+ "title": "Config the name and color!"
28
+ }
29
+ ],
30
+ "configuration": {
31
+ "type": "object",
32
+ "title": "Project Name In StatusBar extension configuration",
33
+ "properties": {
34
+ "fine-me.colorful": {
35
+ "type": "boolean",
36
+ "default": true,
37
+ "description": "Use color"
38
+ },
39
+ "fine-me.color": {
40
+ "type": "string",
41
+ "default": "",
42
+ "description": "The color of status text. When not defined, a random color will be used based on the project name"
43
+ },
44
+ "fine-me.align": {
45
+ "type": "string",
46
+ "enum": [
47
+ "left",
48
+ "right"
49
+ ],
50
+ "default": "left",
51
+ "description": "Defines The alignment of the label, requires restart of vscode"
52
+ },
53
+ "fine-me.alignPriority": {
54
+ "type": "number",
55
+ "default": 100000,
56
+ "description": "Defines The priority of the label, Higher values mean the label should be shown more to the left or right,requires restart of vscode"
57
+ },
58
+ "fine-me.projectSetting": {
59
+ "type": "object",
60
+ "default": {},
61
+ "description": "Project preference"
62
+ },
63
+ "fine-me.textTransform": {
64
+ "type": "string",
65
+ "enum": [
66
+ "none",
67
+ "capitalize",
68
+ "uppercase",
69
+ "lowercase"
70
+ ],
71
+ "default": "capitalize",
72
+ "description": "Defines project name text style inside template"
73
+ }
74
+ }
75
+ }
76
+ },
77
+ "devDependencies": {
78
+ "@types/mocha": "^10.0.10",
79
+ "@types/node": "20.x",
80
+ "@types/vscode": "^1.97.0",
81
+ "@vscode/vsce": "^3.2.2",
82
+ "eslint": "^9.19.0",
83
+ "typescript": "^5.7.3"
84
+ },
85
+ "scripts": {
86
+ "vscode:prepublish": "pnpm run compile",
87
+ "compile": "tsc -p ./",
88
+ "watch": "tsc -watch -p ./",
89
+ "lint": "eslint src",
90
+ "package": "pnpm vsce package --no-dependencies"
91
+ }
92
+ }
@@ -0,0 +1,185 @@
1
+ import path from "path";
2
+ import { commands, window, workspace } from "vscode";
3
+ import {
4
+ ExtensionContext,
5
+ StatusBarAlignment,
6
+ TextEditor,
7
+ Disposable,
8
+ } from "vscode";
9
+
10
+ type ProjectSetting = Record<
11
+ string,
12
+ Partial<{
13
+ color: string;
14
+ name: string;
15
+ icon: string;
16
+ }>
17
+ >;
18
+
19
+ function getProjectPath(): string | undefined {
20
+ if (Array.isArray(workspace.workspaceFolders)) {
21
+ if (workspace.workspaceFolders.length === 1) {
22
+ return workspace.workspaceFolders[0].uri.path;
23
+ } else if (workspace.workspaceFolders.length > 1) {
24
+ const activeTextEditor: TextEditor | undefined = window.activeTextEditor;
25
+ if (activeTextEditor) {
26
+ const workspaceFolder = workspace.workspaceFolders.find(
27
+ (folder: any) => {
28
+ activeTextEditor.document.uri.path.startsWith(folder.uri.path);
29
+ }
30
+ );
31
+ if (workspaceFolder) {
32
+ return workspaceFolder.uri.path;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ function getAlign(): StatusBarAlignment {
40
+ const align: string = workspace
41
+ .getConfiguration("fine-me")
42
+ .get("align") as string;
43
+ switch (align) {
44
+ case "left":
45
+ return StatusBarAlignment.Left;
46
+ case "right":
47
+ return StatusBarAlignment.Right;
48
+ default:
49
+ return StatusBarAlignment.Left;
50
+ }
51
+ }
52
+
53
+ function getProjectSetting(): ProjectSetting {
54
+ return workspace
55
+ .getConfiguration("fine-me")
56
+ .get("projectSetting") as ProjectSetting;
57
+ }
58
+
59
+ function getColorful(): boolean {
60
+ return workspace.getConfiguration("fine-me").get("colorful") as boolean;
61
+ }
62
+
63
+ function getColor(): string {
64
+ return workspace.getConfiguration("fine-me").get("color") as string;
65
+ }
66
+
67
+ function getTextTransform(): string {
68
+ return workspace.getConfiguration("fine-me").get("textTransform") as string;
69
+ }
70
+
71
+ function alignPriority(): number {
72
+ return +(workspace
73
+ .getConfiguration("fine-me")
74
+ .get("alignPriority") as string);
75
+ }
76
+
77
+ const textTransforms: Record<string, (t: string) => string> = {
78
+ uppercase: (t: string) => t.toUpperCase(),
79
+ lowercase: (t: string) => t.toLowerCase(),
80
+ capitalize: (t: string) => t.charAt(0).toUpperCase() + t.slice(1),
81
+ };
82
+
83
+ function getProjectName(projectPath: string): string {
84
+ const projectName = path.basename(projectPath);
85
+ const transform = getTextTransform();
86
+
87
+ if (textTransforms[transform]) {
88
+ return textTransforms[transform](projectName);
89
+ }
90
+ return projectName;
91
+ }
92
+
93
+ function stringToColor(str: string): string {
94
+ let hash = 0;
95
+ for (let i = 0; i < str.length; i++) {
96
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
97
+ }
98
+ let color = "#";
99
+ for (let i = 0; i < 3; i++) {
100
+ const value = (hash >> (i * 8)) & 0xff;
101
+ color += ("00" + value.toString(16)).substr(-2);
102
+ }
103
+ return color;
104
+ }
105
+
106
+ function getProjectColor(projectName: string) {
107
+ if (!getColorful()) {
108
+ return;
109
+ }
110
+
111
+ if (!projectName) {
112
+ return getColor() || undefined;
113
+ }
114
+
115
+ return getColor() || stringToColor(projectName);
116
+ }
117
+
118
+ export function activate(context: ExtensionContext) {
119
+ const statusBarItem = window.createStatusBarItem(getAlign(), alignPriority());
120
+ let projectPath: string | undefined;
121
+ let projectName = "";
122
+ let statusBarName: string | undefined;
123
+ let statusBarColor: string | undefined;
124
+
125
+ let onDidChangeWorkspaceFoldersDisposable: Disposable | undefined;
126
+ let onDidChangeActiveTextEditorDisposable: Disposable | undefined;
127
+
128
+ function updateStatusBarItem() {
129
+ projectPath = getProjectPath();
130
+ console.log("projectPath", projectPath);
131
+ if (!projectPath) {
132
+ statusBarItem.text = "";
133
+ statusBarItem.hide();
134
+ return;
135
+ }
136
+
137
+ const projectSetting = getProjectSetting()[projectPath];
138
+ projectName = projectSetting?.name || getProjectName(projectPath);
139
+
140
+ statusBarItem.text = `${projectName}`;
141
+ statusBarColor = projectSetting?.color || getProjectColor(projectName);
142
+ statusBarItem.color = statusBarColor;
143
+ statusBarItem.command = "workbench.action.quickSwitchWindow";
144
+ statusBarItem.show();
145
+ }
146
+
147
+ function updateSubscription() {
148
+ console.log(
149
+ "onDidChangeWorkspaceFoldersDisposable",
150
+ onDidChangeWorkspaceFoldersDisposable
151
+ );
152
+
153
+ if (!onDidChangeWorkspaceFoldersDisposable) {
154
+ onDidChangeWorkspaceFoldersDisposable =
155
+ workspace.onDidChangeWorkspaceFolders(() => {
156
+ console.log("onDidChangeWorkspaceFolders");
157
+ updateSubscription();
158
+ updateStatusBarItem();
159
+ });
160
+ }
161
+
162
+ console.log("workspace.workspaceFolders", workspace.workspaceFolders);
163
+ if (Array.isArray(workspace.workspaceFolders)) {
164
+ if (workspace.workspaceFolders.length > 1) {
165
+ if (!onDidChangeActiveTextEditorDisposable) {
166
+ onDidChangeActiveTextEditorDisposable =
167
+ window.onDidChangeActiveTextEditor(() => {
168
+ updateStatusBarItem();
169
+ });
170
+ }
171
+ } else {
172
+ if (onDidChangeActiveTextEditorDisposable) {
173
+ onDidChangeActiveTextEditorDisposable.dispose();
174
+ }
175
+ }
176
+ }
177
+ }
178
+
179
+ context.subscriptions.push(statusBarItem);
180
+
181
+ updateSubscription();
182
+ updateStatusBarItem();
183
+ }
184
+
185
+ export function deactivate() {}
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "CommonJS",
4
+ "target": "ES2022",
5
+ "lib": ["ESNext"],
6
+ "sourceMap": true,
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "outDir": "out",
10
+ "esModuleInterop": true
11
+ }
12
+ }