vscode-find-me 0.0.2

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
@@ -0,0 +1,16 @@
1
+ import ganghu from '@ganghu/eslint-config'
2
+
3
+ export default ganghu(
4
+ {
5
+ typescript: true,
6
+ vue: true,
7
+ overrides: {
8
+ typescript: {
9
+ 'no-console': 'warn',
10
+ },
11
+ },
12
+ },
13
+ {
14
+ ignores: ['node_modules'],
15
+ },
16
+ )
package/icon/logo.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "vscode-find-me",
3
+ "displayName": "Find Me",
4
+ "description": "Identify you current working folder in status bar",
5
+ "version": "0.0.2",
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
+ "@ganghu/eslint-config": "^1.0.0",
79
+ "@types/mocha": "^10.0.10",
80
+ "@types/node": "20.x",
81
+ "@types/vscode": "^1.97.0",
82
+ "@vscode/vsce": "^3.2.2",
83
+ "eslint": "^9.22.0",
84
+ "typescript": "^5.7.3"
85
+ },
86
+ "scripts": {
87
+ "vscode:prepublish": "pnpm run compile",
88
+ "compile": "tsc -p ./",
89
+ "watch": "tsc -watch -p ./",
90
+ "lint": "eslint src",
91
+ "package": "pnpm vsce package --no-dependencies"
92
+ }
93
+ }
@@ -0,0 +1,180 @@
1
+ import path from 'path'
2
+ import { commands, window, workspace } from 'vscode'
3
+ import type { ExtensionContext,
4
+ TextEditor,
5
+ Disposable } from 'vscode'
6
+ import {
7
+ StatusBarAlignment,
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
+ }
24
+ else if (workspace.workspaceFolders.length > 1) {
25
+ const activeTextEditor: TextEditor | undefined = window.activeTextEditor
26
+ if (activeTextEditor) {
27
+ const workspaceFolder = workspace.workspaceFolders.find(
28
+ (folder: any) => {
29
+ return activeTextEditor.document.uri.path.startsWith(folder.uri.path)
30
+ },
31
+ )
32
+ if (workspaceFolder) {
33
+ return workspaceFolder.uri.path
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ function getAlign(): StatusBarAlignment {
41
+ const align: string = workspace
42
+ .getConfiguration('fine-me')
43
+ .get('align') as string
44
+ switch (align) {
45
+ case 'left':
46
+ return StatusBarAlignment.Left
47
+ case 'right':
48
+ return StatusBarAlignment.Right
49
+ default:
50
+ return StatusBarAlignment.Left
51
+ }
52
+ }
53
+
54
+ function getProjectSetting(): ProjectSetting {
55
+ return workspace
56
+ .getConfiguration('fine-me')
57
+ .get('projectSetting') as ProjectSetting
58
+ }
59
+
60
+ function getColorful(): boolean {
61
+ return workspace.getConfiguration('fine-me').get('colorful') as boolean
62
+ }
63
+
64
+ function getColor(): string {
65
+ return workspace.getConfiguration('fine-me').get('color') as string
66
+ }
67
+
68
+ function getTextTransform(): string {
69
+ return workspace.getConfiguration('fine-me').get('textTransform') as string
70
+ }
71
+
72
+ function alignPriority(): number {
73
+ return +(workspace
74
+ .getConfiguration('fine-me')
75
+ .get('alignPriority') as string)
76
+ }
77
+
78
+ const textTransforms: Record<string, (t: string) => string> = {
79
+ uppercase: (t: string) => t.toUpperCase(),
80
+ lowercase: (t: string) => t.toLowerCase(),
81
+ capitalize: (t: string) => t.charAt(0).toUpperCase() + t.slice(1),
82
+ }
83
+
84
+ function getProjectName(projectPath: string): string {
85
+ const projectName = path.basename(projectPath)
86
+ const transform = getTextTransform()
87
+
88
+ if (textTransforms[transform]) {
89
+ return textTransforms[transform](projectName)
90
+ }
91
+ return projectName
92
+ }
93
+
94
+ function stringToColor(str: string): string {
95
+ let hash = 0
96
+ for (let i = 0; i < str.length; i++) {
97
+ hash = str.charCodeAt(i) + ((hash << 5) - hash)
98
+ }
99
+ let color = '#'
100
+ for (let i = 0; i < 3; i++) {
101
+ const value = (hash >> (i * 8)) & 0xff
102
+ color += (`00${value.toString(16)}`).substr(-2)
103
+ }
104
+ return color
105
+ }
106
+
107
+ function getProjectColor(projectName: string) {
108
+ if (!getColorful()) {
109
+ return
110
+ }
111
+
112
+ if (!projectName) {
113
+ return getColor() || undefined
114
+ }
115
+
116
+ return getColor() || stringToColor(projectName)
117
+ }
118
+
119
+ export function activate(context: ExtensionContext) {
120
+ const statusBarItem = window.createStatusBarItem(getAlign(), alignPriority())
121
+ let projectPath: string | undefined
122
+ let projectName = ''
123
+ let statusBarName: string | undefined
124
+ let statusBarColor: string | undefined
125
+
126
+ let onDidChangeWorkspaceFoldersDisposable: Disposable | undefined
127
+ let onDidChangeActiveTextEditorDisposable: Disposable | undefined
128
+
129
+ function updateStatusBarItem() {
130
+ projectPath = getProjectPath()
131
+
132
+ if (!projectPath) {
133
+ statusBarItem.text = ''
134
+ statusBarItem.hide()
135
+ return
136
+ }
137
+
138
+ const projectSetting = getProjectSetting()[projectPath]
139
+ projectName = projectSetting?.name || getProjectName(projectPath)
140
+
141
+ statusBarItem.text = `${projectName}`
142
+ statusBarColor = projectSetting?.color || getProjectColor(projectName)
143
+ statusBarItem.color = statusBarColor
144
+ statusBarItem.command = 'workbench.action.quickSwitchWindow'
145
+ statusBarItem.show()
146
+ }
147
+
148
+ function updateSubscription() {
149
+ if (!onDidChangeWorkspaceFoldersDisposable) {
150
+ onDidChangeWorkspaceFoldersDisposable
151
+ = workspace.onDidChangeWorkspaceFolders(() => {
152
+ updateSubscription()
153
+ updateStatusBarItem()
154
+ })
155
+ }
156
+
157
+ if (Array.isArray(workspace.workspaceFolders)) {
158
+ if (workspace.workspaceFolders.length > 1) {
159
+ if (!onDidChangeActiveTextEditorDisposable) {
160
+ onDidChangeActiveTextEditorDisposable
161
+ = window.onDidChangeActiveTextEditor(() => {
162
+ updateStatusBarItem()
163
+ })
164
+ }
165
+ }
166
+ else {
167
+ if (onDidChangeActiveTextEditorDisposable) {
168
+ onDidChangeActiveTextEditorDisposable.dispose()
169
+ }
170
+ }
171
+ }
172
+ }
173
+
174
+ context.subscriptions.push(statusBarItem)
175
+
176
+ updateSubscription()
177
+ updateStatusBarItem()
178
+ }
179
+
180
+ export function deactivate() {}
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "CommonJS",
4
+ "target": "ES2022",
5
+ "lib": ["ESNext"],
6
+ "sourceMap": true,
7
+ "strict": true,
8
+ "outDir": "out",
9
+ "esModuleInterop": true
10
+ },
11
+ "include": ["**/*.ts"],
12
+ "exclude": []
13
+ }