├── .editorconfig ├── .github └── workflows │ ├── ci.yaml │ └── lint.yml ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── biome.json ├── images ├── command-palette.png ├── icon.png ├── icon.svg └── image.gif ├── package-lock.json ├── package.json ├── src ├── config.ts ├── currentFile.ts ├── editorChangeListner.ts ├── extension.ts ├── quickPicker.ts ├── test │ ├── runLatestTest.ts │ ├── runMinSupportVersionTest.ts │ └── suite │ │ ├── extensions.test.ts │ │ └── index.ts └── utils │ └── types.ts ├── testTmp ├── .gitkeep └── README.md └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [*.ts] 11 | indent_size = 4 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | 16 | [*.json] 17 | indent_size = 2 18 | indent_style = space 19 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | os: [ubuntu-latest, macos-latest, windows-latest] 12 | node-version: ['22.x'] 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Setup Node.js 16 | uses: actions/setup-node@v4 17 | - name: Install Dependencies 18 | run: npm install 19 | - name: Compile TypeScript 20 | run: npm run compile 21 | - name: Run headless tests - specific version 22 | uses: coactions/setup-xvfb@v1 23 | with: 24 | run: npm run test:minSupportVersion 25 | - name: Run headless tests - latest version 26 | uses: coactions/setup-xvfb@v1 27 | with: 28 | run: npm run test:latest 29 | # - name: Run headless tests - legacy version 30 | # uses: coactions/setup-xvfb@v1 31 | # with: 32 | # run: npm run test:legacy 33 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | os: [ubuntu-latest, macos-latest, windows-latest] 12 | node-version: ['22.x'] 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Setup Node.js 16 | uses: actions/setup-node@v4 17 | - name: Install Dependencies 18 | run: npm install 19 | - name: Lint 20 | run: npm run lint 21 | 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | *.log 6 | 7 | testTmp/* 8 | !.gitkeep 9 | !README.md 10 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "eg2.tslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 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": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ], 16 | "outFiles": [ 17 | "${workspaceFolder}/out/**/*.js" 18 | ], 19 | "preLaunchTask": "npm: watch" 20 | }, 21 | { 22 | "name": "Extension Tests", 23 | "type": "extensionHost", 24 | "request": "launch", 25 | "runtimeExecutable": "${execPath}", 26 | "args": [ 27 | "--extensionDevelopmentPath=${workspaceFolder}", 28 | "--extensionTestsPath=${workspaceFolder}/out/test" 29 | ], 30 | "outFiles": [ 31 | "${workspaceFolder}/out/test/**/*.js" 32 | ], 33 | "preLaunchTask": "npm: watch" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 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 | } 21 | -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | out/**/*.map 5 | src/** 6 | .gitignore 7 | .editorconfig 8 | tsconfig.json 9 | vsc-extension-quickstart.md 10 | tslint.json 11 | images/icon.svg 12 | images/image.gif 13 | images/original_image.gif 14 | .github 15 | testTmp/** 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## v4.1.0 - 2024-03-16 4 | 5 | ### Perf 6 | 7 | * [b301697](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/b301697) refactor: use `onStartupFinished` for activate extention event 8 | 9 | ### Others 10 | 11 | * [097d8b9](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/097d8b9) docs: update LICENSE year 12 | * [03db2f9](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/03db2f9) docs: update images 13 | * [eb18992](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/eb18992) chore: require `npm+10` 14 | * [80f41f6](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/80f41f6) chore: require `node+20` 15 | * [3d5ffbb](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/3d5ffbb) chore: replace `tab` to `space2` in `package.json` 16 | * [88fe063](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/88fe063) ci: update actions 17 | * [ee4e074](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/ee4e074) chore(deps): bump `@vscode/vsce` and `@vscode/test-electron` 18 | * [9048839](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/9048839) ci: ignore `fail-fast` 19 | * [a400bc5](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/a400bc5) chore: delete unnecessary file 20 | * [691f3de](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/691f3de) test: change `mocha` default timeout 21 | * [fd9a8e1](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/fd9a8e1) chore(deps): update dependencies 22 | * [23a31c9](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/23a31c9) chore(deps): bump `blob` from `8.0.3` to `10.3.10` 23 | 24 | ## v4.0.0 - 2023-05-05 25 | 26 | ### Breaking Changes 27 | 28 | * Require VSCode 1.70+ 29 | * [7eed663](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/7eed663) chore: require 1.70+ follow-up 1db4c3567c42a303dd6f306b796cf6b23523c3dc 30 | * [1db4c35](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/1db4c35) chore: require v1.70.0+ 31 | 32 | ### Othres 33 | 34 | Refactor & Cleanups. Nothing, new features, bug fixes. 35 | 36 | * [430827f](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/430827f) docs: delete release details in `README` 37 | * [0098057](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/0098057) chore(deps): `@vscode/test-electron` move from `dependencies` to `devDependencies` 38 | * [858764d](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/858764d) refactor: use `@vscode/vsce` instead of `vsce` 39 | * [8f092f2](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/8f092f2) chore(deps): fixed package versions 40 | * [aa551bd](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/aa551bd) refactor: delete `use strict` 41 | * [5852060](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/5852060) chore: reformat `package.json` 42 | * [bf1476c](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/bf1476c) test: workaround for MacOS test issue 43 | * [c33cd06](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/c33cd06) test: use `@vscode/test-electron` instead of `vscode-test` 44 | * [065901b](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/065901b) test: put stacktrace when test failed 45 | * [05978c4](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/05978c4) test: rename test file and its task 46 | * [ecebcc5](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/ecebcc5) fix: error change in a2c92cb18f93459e61e2fc40dc4101637cb1195e 47 | * [305908d](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/305908d) refactor: clean up `eslint` and `prettier` 48 | * [a2c92cb](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/a2c92cb) refactor: `requrie` to `import` 49 | * [9e60d4b](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/9e60d4b) refactor: use `number` instead of `Number` 50 | * [7693cba](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/7693cba) refactor: explicity nothing todo 51 | * [16f3399](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/16f3399) refactor: use `const` instead of `let` 52 | * [448fb65](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/448fb65) test: drop regacy legacy version test 53 | * [d26c95d](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/d26c95d) chore(ci): migrate GitHub Actions 54 | * [f4e2156](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/f4e2156) chore(deps): update devDependencies 55 | * [5ce42f5](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/5ce42f5) docs: update badge 56 | * [d7aaa10](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/d7aaa10) chore(ci): add node.js 18.x matrix buil 57 | * [e04664d](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/e04664d) chore(ci): update GitHub Actions 58 | * [f4855e3](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/f4855e3) chore: delete `__metadata` from `package.json` 59 | * [8e6adf4](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/8e6adf4) require: node.js 16+ 60 | * [7d6ddff](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/7d6ddff) chore: require `npm8+` & `node14+` 61 | * [138edd3](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/138edd3) chore: tab to space 62 | * [c83ca68](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/c83ca68) chore(deps): update dependencies for vscode 63 | * [b102121](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/b102121) chore(deps): update dependencies 64 | * [a02e5c0](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/a02e5c0) chore: update .vscodeignore 65 | * [f5a2ba2](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/f5a2ba2) chore: ts-ignore 66 | * [bd299fb](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/bd299fb) chore(deps): update dependencies 67 | * [9069e35](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/9069e35) chore: require npm +7 68 | * [e93f9c5](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/e93f9c5) chore: update LICENSE year 69 | * [8d923d0](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/8d923d0) chore: uppercase to lowercase 70 | * [9e09082](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/9e09082) chore(deps): update some devDependencies 71 | * [454a150](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/454a150) chore: bump engine from node 10.x to 12.x 72 | 73 | ## v3.1.0 - 2021-02-11 74 | 75 | ### New features 76 | 77 | * (refs [#151](https://github.com/yoshinorin/vscode-current-file-path-extension/pull/151)): Support copy feature on the remote-host [@dlguswo333](https://github.com/dlguswo333) 78 | * e.g. Remote-WSL, Remote-Linux 79 | * replace `clipboardy` with `vscode.env.clipboard` 80 | 81 | ### Misc 82 | 83 | * [f735692](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/f735692fd2ae51f8c317664716c86a731e501b41): update some devDependencies 84 | 85 | ## v3.0.0 - 2020-05-29 86 | 87 | ### Breaking change 88 | 89 | * [6664105](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/66641059a8263cf4d9d70986b5f424d65b6d5f38): Bump min support VSCode version from `1.18.0` to `1.40.0` 90 | 91 | ### New features 92 | 93 | * [5811830](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/58118304a2a068b69fa544b3268bee578615f0fb): Add open extension settings 94 | 95 | ### Misc 96 | 97 | * (refs [#144](https://github.com/yoshinorin/vscode-current-file-path-extension/pull/144)), [f56d3fde](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/f56d3fde4855902d8f54aefd4a10e4f62d8c90b7), [339b2400](https://github.com/yoshinorin/vscode-current-file-path-extension/commit/339b240067e161b292da25160a4223278539a313): Add unit test 98 | * (refs [#143](https://github.com/yoshinorin/vscode-current-file-path-extension/pull/143)): Add CI (GitHub Action) 99 | * Update some dependencies 100 | 101 | ## v2.0.0 - 2018-09-04 102 | 103 | ### Breaking change 104 | 105 | `fromWorkSpaceOrNot` setting changed to `defaultPathStartsFrom`. Please change your setting if use. 106 | 107 | ### New feature 108 | 109 | * (refs [#16](https://github.com/yoshinorin/vscode-current-file-path-extension/issues/16)) All action callable from command palette. 110 | * (refs [#19](https://github.com/yoshinorin/vscode-current-file-path-extension/issues/19)) Implement copy file name feature. 111 | 112 | ### Bug fix 113 | 114 | * (refs [#21](https://github.com/yoshinorin/vscode-current-file-path-extension/issues/21)) Can not get correct each root folder path if workspace has some folders. 115 | 116 | ### Others 117 | 118 | * Change some UI 119 | * Improve wording 120 | 121 | ## v1.0.0 - 2018-05-16 122 | 123 | * Initial release 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 - 2024 yoshinorin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Current File Path for Visual Studio Code 2 | 3 | ![](https://img.shields.io/badge/Release-v4.0.0-blue.svg?style=flat-square) 4 | ![](https://img.shields.io/badge/vscode-^1.70.0-blue.svg?style=flat-square) 5 | [![CI](https://github.com/yoshinorin/vscode-current-file-path-extension/actions/workflows/ci.yaml/badge.svg)](https://github.com/yoshinorin/vscode-current-file-path-extension/actions/workflows/ci.yaml) 6 | 7 | Visual Studio Code extension. This extension displays a current file path from absolute (root directory) or workspace highest directory in StatusBar by Unix style or Windows style. 8 | 9 | ## Features 10 | 11 | * Display a current file's path in the StatusBar. 12 | * Absolute (root directory) or starts from workspace highest directory 13 | * You can select which to use by settings. 14 | * You can change the path appearance with QuickPick or command palette. 15 | * Path separator style can choose Unix or Windows. 16 | * You can select which to use by settings. 17 | * You can change it with QuickPick or command palette. 18 | * Copy a current file path to clipboard. 19 | * Copy a current file name to clipboard. 20 | * Support copy feature on the remote-host. 21 | * e.g. Remote-WSL, Remote-Linux 22 | * You can set a display priority in the StatusBar by setting. 23 | 24 | ## Images 25 | 26 | ![](https://raw.githubusercontent.com/yoshinorin/vscode-current-file-path-extension/master/images/image.gif) 27 | 28 | **Command Palette** 29 | 30 | ![](https://raw.githubusercontent.com/yoshinorin/vscode-current-file-path-extension/master/images/command-palette.png) 31 | 32 | ## Extension Settings 33 | 34 | |Property|Description|value|Default| 35 | |---|---|---|---| 36 | |`currentFilePath.defaultPathStyle`|Specify default path style. Unix like or Windows like.|`unix`
`windows`|`unix`| 37 | |`currentFilePath.priorityInStatusBar`|The priority in the statusBar. Higher values shown more to the left.| `0` ~ max int |`0`| 38 | |`currentFilePath.defaultPathStartsFrom`|Default value of where the path is displayed starts from. Root directory or workspace highest directory.|`rootDirectory`
`workSpace`|`rootDirectory`| 39 | 40 | ## Requirements 41 | 42 | * Visual Studio Code 1.70.0 later 43 | * Linux will probably have to install [xsel](https://linux.die.net/man/1/xsel). 44 | * e.g.) Debian/Ubuntu `sudo apt install xsel` 45 | 46 | ## Release Notes 47 | 48 | Please see [releases](https://github.com/yoshinorin/vscode-current-file-path-extension/releases). 49 | -------------------------------------------------------------------------------- /biome.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", 3 | "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false }, 4 | "files": { "ignoreUnknown": false, "ignore": ["*.json", "**/node_modules/**"] }, 5 | "formatter": { "enabled": true, "indentStyle": "space" }, 6 | "organizeImports": { "enabled": true }, 7 | "linter": { 8 | "enabled": true, 9 | "rules": { 10 | "recommended": false, 11 | "complexity": { 12 | "noBannedTypes": "error", 13 | "noExtraBooleanCast": "error", 14 | "noMultipleSpacesInRegularExpressionLiterals": "error", 15 | "noUselessCatch": "error", 16 | "noUselessTypeConstraint": "error", 17 | "noWith": "error" 18 | }, 19 | "correctness": { 20 | "noConstAssign": "error", 21 | "noConstantCondition": "error", 22 | "noEmptyCharacterClassInRegex": "error", 23 | "noEmptyPattern": "error", 24 | "noGlobalObjectCalls": "error", 25 | "noInnerDeclarations": "error", 26 | "noInvalidConstructorSuper": "error", 27 | "noNewSymbol": "error", 28 | "noNonoctalDecimalEscape": "error", 29 | "noPrecisionLoss": "error", 30 | "noSelfAssign": "error", 31 | "noSetterReturn": "error", 32 | "noSwitchDeclarations": "error", 33 | "noUndeclaredVariables": "warn", 34 | "noUnreachable": "error", 35 | "noUnreachableSuper": "error", 36 | "noUnsafeFinally": "error", 37 | "noUnsafeOptionalChaining": "error", 38 | "noUnusedLabels": "error", 39 | "noUnusedVariables": "error", 40 | "useArrayLiterals": "off", 41 | "useIsNan": "error", 42 | "useValidForDirection": "error", 43 | "useYield": "error" 44 | }, 45 | "style": { "noNamespace": "error", "useAsConstAssertion": "error" }, 46 | "suspicious": { 47 | "noAsyncPromiseExecutor": "error", 48 | "noCatchAssign": "error", 49 | "noClassAssign": "error", 50 | "noCompareNegZero": "error", 51 | "noControlCharactersInRegex": "error", 52 | "noDebugger": "error", 53 | "noDuplicateCase": "error", 54 | "noDuplicateClassMembers": "error", 55 | "noDuplicateObjectKeys": "error", 56 | "noDuplicateParameters": "error", 57 | "noEmptyBlockStatements": "error", 58 | "noExplicitAny": "error", 59 | "noExtraNonNullAssertion": "error", 60 | "noFallthroughSwitchClause": "error", 61 | "noFunctionAssign": "error", 62 | "noGlobalAssign": "error", 63 | "noImportAssign": "error", 64 | "noMisleadingCharacterClass": "error", 65 | "noMisleadingInstantiator": "error", 66 | "noPrototypeBuiltins": "error", 67 | "noRedeclare": "error", 68 | "noShadowRestrictedNames": "error", 69 | "noSparseArray": "error", 70 | "noUnsafeDeclarationMerging": "error", 71 | "noUnsafeNegation": "error", 72 | "useGetterReturn": "error", 73 | "useValidTypeof": "error" 74 | } 75 | }, 76 | "ignore": ["out/*", "**/*.js", "*.json"] 77 | }, 78 | "javascript": { "formatter": { "quoteStyle": "double" } }, 79 | "overrides": [ 80 | { 81 | "include": ["*.ts"], 82 | "linter": { 83 | "rules": { 84 | "correctness": { "noUnusedVariables": "error" }, 85 | "style": { 86 | "noInferrableTypes": "off", 87 | "noNonNullAssertion": "error", 88 | "noVar": "error", 89 | "useBlockStatements": "error" 90 | }, 91 | "suspicious": { "noExplicitAny": "off" } 92 | } 93 | } 94 | } 95 | ] 96 | } 97 | -------------------------------------------------------------------------------- /images/command-palette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoshinorin/vscode-current-file-path-extension/bc89516a623d9e4938c45c5bbf8d40d594ad23e2/images/command-palette.png -------------------------------------------------------------------------------- /images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoshinorin/vscode-current-file-path-extension/bc89516a623d9e4938c45c5bbf8d40d594ad23e2/images/icon.png -------------------------------------------------------------------------------- /images/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /images/image.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoshinorin/vscode-current-file-path-extension/bc89516a623d9e4938c45c5bbf8d40d594ad23e2/images/image.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "current-file-path", 3 | "displayName": "Current File Path", 4 | "description": "Display current file's path from absolute (root directory) or workspace highest directory in StatusBar by Unix style or Windows style.", 5 | "version": "4.1.0", 6 | "publisher": "yoshinorin", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/yoshinorin/vscode-current-file-path-extension" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/yoshinorin/vscode-current-file-path-extension/issues" 13 | }, 14 | "license": "MIT", 15 | "engines": { 16 | "node": ">=22", 17 | "npm": ">=10", 18 | "vscode": "^1.70.0" 19 | }, 20 | "categories": [ 21 | "Other" 22 | ], 23 | "keywords": [ 24 | "copy", 25 | "file", 26 | "path" 27 | ], 28 | "icon": "images/icon.png", 29 | "activationEvents": [ 30 | "onStartupFinished" 31 | ], 32 | "main": "./out/extension", 33 | "contributes": { 34 | "configuration": { 35 | "type": "object", 36 | "title": "Current File Path extention configurations", 37 | "properties": { 38 | "currentFilePath.defaultPathStyle": { 39 | "type": "string", 40 | "default": "unix", 41 | "enum": [ 42 | "unix", 43 | "windows" 44 | ], 45 | "description": "Specify default path style. Unix like or Windows like.", 46 | "scope": "window" 47 | }, 48 | "currentFilePath.priorityInStatusBar": { 49 | "type": "number", 50 | "default": 0, 51 | "description": "The priority in the statusBar. Higher values shown more to the left.", 52 | "scope": "window" 53 | }, 54 | "currentFilePath.defaultPathStartsFrom": { 55 | "type": "string", 56 | "default": "rootDirectory", 57 | "enum": [ 58 | "rootDirectory", 59 | "workSpace" 60 | ], 61 | "description": "Default value of where the path is displayed starts from. Root directory or workspace highest directory.", 62 | "scope": "window" 63 | } 64 | } 65 | }, 66 | "commands": [ 67 | { 68 | "command": "currentFilePath.executeQuickPickerAction", 69 | "title": "Current File Path: Open Menus", 70 | "group": "current-file-path" 71 | }, 72 | { 73 | "command": "currentFilePath.viewUnixStyle", 74 | "title": "Current File Path: UNIX style", 75 | "group": "current-file-path" 76 | }, 77 | { 78 | "command": "currentFilePath.viewWindowsStyle", 79 | "title": "Current File Path: Windows style", 80 | "group": "current-file-path" 81 | }, 82 | { 83 | "command": "currentFilePath.viewFromSystemRoot", 84 | "title": "Current File Path: Absolute path", 85 | "group": "current-file-path" 86 | }, 87 | { 88 | "command": "currentFilePath.viewFromWorkSpaceRoot", 89 | "title": "Current File Path: From workspace root path", 90 | "group": "current-file-path" 91 | }, 92 | { 93 | "command": "currentFilePath.copy", 94 | "title": "Current File Path: Copy (Path)", 95 | "group": "current-file-path" 96 | }, 97 | { 98 | "command": "currentFilePath.copyFileName", 99 | "title": "Current File Path: Copy (FileName)", 100 | "group": "current-file-path" 101 | }, 102 | { 103 | "command": "currentFilePath.copyFileNameWithOutExtension", 104 | "title": "Current File Path: Copy (FileName without extension)", 105 | "group": "current-file-path" 106 | }, 107 | { 108 | "command": "currentFilePath.openSettings", 109 | "title": "Current File Path: Open Extension Settings", 110 | "group": "current-file-path" 111 | } 112 | ] 113 | }, 114 | "scripts": { 115 | "vscode:prepublish": "npm install && npm run lint && npm run compile", 116 | "compile": "tsc -p ./", 117 | "watch": "tsc -watch -p ./", 118 | "pretest": "npm run compile", 119 | "lint": "biome lint --write ./src", 120 | "fmt": "biome format --write ./src", 121 | "test:minSupportVersion": " node ./out/test/runMinSupportVersionTest.js", 122 | "test:latest": " node ./out/test/runLatestTest.js", 123 | "test": "npm run test:minSupportVersion && npm run test:latest", 124 | "prepackage": "npm install && npm run lint && npm run compile", 125 | "package": "vsce package" 126 | }, 127 | "devDependencies": { 128 | "@biomejs/biome": "1.9.4", 129 | "@types/mocha": "10.0.10", 130 | "@types/node": "22.14.0", 131 | "@types/vscode": "1.98.0", 132 | "@vscode/test-electron": "2.4.1", 133 | "@vscode/vsce": "3.3.2", 134 | "glob": "11.0.1", 135 | "mocha": "11.1.0", 136 | "typescript": "5.8.2" 137 | }, 138 | "__metadata": { 139 | "id": "ceb1d4ae-8b8e-4f60-bb3a-3a3710b3dc0f", 140 | "publisherDisplayName": "yoshinorin", 141 | "publisherId": "3d54fa26-24ac-4aa9-ba58-7ba481e515fc", 142 | "isPreReleaseVersion": false 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/config.ts: -------------------------------------------------------------------------------- 1 | import { window, workspace } from "vscode"; 2 | 3 | export class Config { 4 | private readonly _config: any; 5 | 6 | private readonly _defaultPathStyle: string = ""; 7 | public get defaultPathStyle(): string { 8 | return this._defaultPathStyle; 9 | } 10 | 11 | private readonly _priorityInStatusBar: number = 0; 12 | public get priorityInStatusBar(): number { 13 | return this._priorityInStatusBar; 14 | } 15 | 16 | private readonly _defaultPathStartsFrom: string = ""; 17 | public get defaultPathStartsFrom(): string { 18 | return this._defaultPathStartsFrom; 19 | } 20 | 21 | constructor() { 22 | try { 23 | this._config = workspace.getConfiguration("currentFilePath"); 24 | this._defaultPathStyle = this._config.defaultPathStyle; 25 | this._priorityInStatusBar = this._config.priorityInStatusBar; 26 | this._defaultPathStartsFrom = this._config.defaultPathStartsFrom; 27 | } catch (ex) { 28 | // @ts-ignore 29 | window.showErrorMessage(ex.message); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/currentFile.ts: -------------------------------------------------------------------------------- 1 | import { 2 | commands, 3 | StatusBarAlignment, 4 | StatusBarItem, 5 | window, 6 | workspace, 7 | env, 8 | } from "vscode"; 9 | import { Config } from "./config"; 10 | import { QuickPicker, QuickPickerAction } from "./quickPicker"; 11 | import { PathStyles, PathStartsFrom } from "./utils/types"; 12 | import { join, basename } from "path"; 13 | const clipboard = env.clipboard; 14 | 15 | export class CurrentFile { 16 | private readonly _config: Config; 17 | private get config(): Config { 18 | return this._config; 19 | } 20 | 21 | private readonly _quickPicker: QuickPicker; 22 | private get quickPicker(): QuickPicker { 23 | return this._quickPicker; 24 | } 25 | 26 | private readonly _statusBarItem: StatusBarItem; 27 | private get statusBarItem(): StatusBarItem { 28 | return this._statusBarItem; 29 | } 30 | 31 | private get isWorkSpace(): boolean { 32 | return workspace.workspaceFolders !== undefined; 33 | } 34 | 35 | private _currentStyle: string; 36 | private get currentStyle(): string { 37 | if (this._currentStyle === PathStyles.UNIX) { 38 | return PathStyles.UNIX; 39 | } 40 | return PathStyles.WINDOWS; 41 | } 42 | private set currentStyle(style: string) { 43 | this._currentStyle = style; 44 | } 45 | 46 | private _currentPathStartsFrom: string; 47 | private get currentPathStartsFrom(): string { 48 | if (this._currentPathStartsFrom === PathStartsFrom.ROOT_DIRECTORY) { 49 | return PathStartsFrom.ROOT_DIRECTORY; 50 | } 51 | return PathStartsFrom.WORK_SPACE; 52 | } 53 | private set currentPathStartsFrom(statingFrom: string) { 54 | this._currentPathStartsFrom = statingFrom; 55 | } 56 | 57 | private _startsFromRootDirectoryPath: string = ""; 58 | private get startsFromRootDirectoryPath(): string { 59 | if (this.currentStyle === PathStyles.UNIX) { 60 | return this.toUnixStyle(this._startsFromRootDirectoryPath); 61 | } 62 | return this.toWindowsStyle(this._startsFromRootDirectoryPath); 63 | } 64 | private set startsFromRootDirectoryPath(path: string) { 65 | this._startsFromRootDirectoryPath = path; 66 | } 67 | 68 | private _startsFromWorkSpaceHighestDirectoryPath: string = ""; 69 | private get startsFromWorkSpaceHighestDirectoryPath(): string { 70 | if (this.currentStyle === PathStyles.UNIX) { 71 | return this.toUnixStyle(this._startsFromWorkSpaceHighestDirectoryPath); 72 | } 73 | return this.toWindowsStyle(this._startsFromWorkSpaceHighestDirectoryPath); 74 | } 75 | private set startsFromWorkSpaceHighestDirectoryPath(path: string) { 76 | const folders = workspace.workspaceFolders; 77 | if (folders === undefined) { 78 | this._startsFromWorkSpaceHighestDirectoryPath = path; 79 | return; 80 | } 81 | const rootFolderObj = folders.find((x) => { 82 | return this.toUnixStyle(path).startsWith(this.toUnixStyle(x.uri.fsPath)); 83 | }); 84 | if (rootFolderObj === undefined) { 85 | this._startsFromWorkSpaceHighestDirectoryPath = path; 86 | return; 87 | } 88 | this._startsFromWorkSpaceHighestDirectoryPath = join( 89 | rootFolderObj.name, 90 | this.toUnixStyle(path).replace( 91 | this.toUnixStyle(rootFolderObj.uri.fsPath), 92 | "", 93 | ), 94 | ); 95 | } 96 | 97 | private _name: string = ""; 98 | private get name(): string { 99 | return this._name; 100 | } 101 | private set name(s: string) { 102 | this._name = s; 103 | } 104 | 105 | constructor() { 106 | this._config = new Config(); 107 | this._quickPicker = new QuickPicker(); 108 | this._currentPathStartsFrom = this.config.defaultPathStartsFrom; 109 | this._currentStyle = this.config.defaultPathStyle; 110 | this._statusBarItem = window.createStatusBarItem( 111 | StatusBarAlignment.Left, 112 | this.config.priorityInStatusBar, 113 | ); 114 | this._statusBarItem.tooltip = "Open Menus"; 115 | this._statusBarItem.command = "currentFilePath.executeQuickPickerAction"; 116 | this.update(); 117 | } 118 | 119 | private toUnixStyle(path: string): string { 120 | return path.replace(/\\/g, "/"); 121 | } 122 | 123 | private toWindowsStyle(path: string): string { 124 | return path.replace(/\//g, "\\"); 125 | } 126 | 127 | private updateStatusBar() { 128 | if (this.currentPathStartsFrom === PathStartsFrom.ROOT_DIRECTORY) { 129 | this.statusBarItem.text = this.startsFromRootDirectoryPath; 130 | } else { 131 | this.statusBarItem.text = this.startsFromWorkSpaceHighestDirectoryPath; 132 | } 133 | } 134 | 135 | public update() { 136 | const editor = window.activeTextEditor; 137 | if (!editor) { 138 | this.statusBarItem.hide(); 139 | return; 140 | } 141 | 142 | this.startsFromRootDirectoryPath = editor.document.uri.fsPath; 143 | this.startsFromWorkSpaceHighestDirectoryPath = editor.document.uri.fsPath; 144 | this.name = basename(editor.document.uri.fsPath); 145 | 146 | this.updateStatusBar(); 147 | this.statusBarItem.show(); 148 | } 149 | 150 | public viewUnixStyle() { 151 | this.currentStyle = PathStyles.UNIX; 152 | this.updateStatusBar(); 153 | } 154 | 155 | public viewWindowsStyle() { 156 | this.currentStyle = PathStyles.WINDOWS; 157 | this.updateStatusBar(); 158 | } 159 | 160 | public viewFromSystemRoot() { 161 | this.currentPathStartsFrom = PathStartsFrom.ROOT_DIRECTORY; 162 | this.updateStatusBar(); 163 | } 164 | 165 | public viewFromWorkSpaceRoot() { 166 | this.currentPathStartsFrom = PathStartsFrom.WORK_SPACE; 167 | this.updateStatusBar(); 168 | } 169 | 170 | public async copy() { 171 | if (this.currentPathStartsFrom === PathStartsFrom.ROOT_DIRECTORY) { 172 | await clipboard.writeText(this.startsFromRootDirectoryPath); 173 | return; 174 | } 175 | await clipboard.writeText(this.startsFromWorkSpaceHighestDirectoryPath); 176 | } 177 | 178 | public async copyFileName() { 179 | await clipboard.writeText(this.name); 180 | } 181 | 182 | public async copyFileNameWithOutExtension() { 183 | await clipboard.writeText(this.name.slice(0, this.name.lastIndexOf("."))); 184 | } 185 | 186 | public openSettings() { 187 | commands.executeCommand( 188 | "workbench.action.openSettings", 189 | "@ext:yoshinorin.current-file-path", 190 | ); 191 | } 192 | 193 | public executeQuickPickerAction() { 194 | this.quickPicker 195 | .getActionId( 196 | this.currentStyle, 197 | this.isWorkSpace, 198 | this.currentPathStartsFrom, 199 | ) 200 | .then((actionId) => { 201 | switch (actionId) { 202 | case QuickPickerAction.viewUnixStyle: 203 | this.viewUnixStyle(); 204 | return; 205 | case QuickPickerAction.viewWindowsStyle: 206 | this.viewWindowsStyle(); 207 | return; 208 | case QuickPickerAction.viewFromSystemRoot: 209 | this.viewFromSystemRoot(); 210 | return; 211 | case QuickPickerAction.viewFromWorkSpaceRoot: 212 | this.viewFromWorkSpaceRoot(); 213 | return; 214 | case QuickPickerAction.copy: 215 | this.copy(); 216 | return; 217 | case QuickPickerAction.copyFileName: 218 | this.copyFileName(); 219 | return; 220 | case QuickPickerAction.copyFileNameWithOutExtension: 221 | this.copyFileNameWithOutExtension(); 222 | return; 223 | case QuickPickerAction.openSettings: 224 | this.openSettings(); 225 | return; 226 | default: 227 | return; 228 | } 229 | }); 230 | } 231 | 232 | dispose() { 233 | this.statusBarItem.dispose(); 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /src/editorChangeListner.ts: -------------------------------------------------------------------------------- 1 | import { CurrentFile } from "./currentFile"; 2 | import { Disposable, window } from "vscode"; 3 | 4 | export class EditorChangeListner { 5 | private _currentFile: CurrentFile; 6 | private _disposable: Disposable; 7 | 8 | private _onEvent() { 9 | this._currentFile.update(); 10 | } 11 | 12 | constructor(currentFile: CurrentFile) { 13 | this._currentFile = currentFile; 14 | 15 | const subscriptions: Disposable[] = []; 16 | window.onDidChangeActiveTextEditor(this._onEvent, this, subscriptions); 17 | this._disposable = Disposable.from(...subscriptions); 18 | } 19 | 20 | dispose() { 21 | this._disposable.dispose(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import { ExtensionContext, commands } from "vscode"; 2 | import { CurrentFile } from "./currentFile"; 3 | import { EditorChangeListner } from "./editorChangeListner"; 4 | 5 | export function activate(context: ExtensionContext) { 6 | const currentFile = new CurrentFile(); 7 | const listner = new EditorChangeListner(currentFile); 8 | 9 | const disposableCommands = [ 10 | commands.registerCommand("currentFilePath.executeQuickPickerAction", () => { 11 | currentFile.executeQuickPickerAction(); 12 | }), 13 | commands.registerCommand("currentFilePath.viewUnixStyle", () => { 14 | currentFile.viewUnixStyle(); 15 | }), 16 | commands.registerCommand("currentFilePath.viewWindowsStyle", () => { 17 | currentFile.viewWindowsStyle(); 18 | }), 19 | commands.registerCommand("currentFilePath.viewFromSystemRoot", () => { 20 | currentFile.viewFromSystemRoot(); 21 | }), 22 | commands.registerCommand("currentFilePath.viewFromWorkSpaceRoot", () => { 23 | currentFile.viewFromWorkSpaceRoot(); 24 | }), 25 | commands.registerCommand("currentFilePath.copy", () => { 26 | currentFile.copy(); 27 | }), 28 | commands.registerCommand("currentFilePath.copyFileName", () => { 29 | currentFile.copyFileName(); 30 | }), 31 | commands.registerCommand( 32 | "currentFilePath.copyFileNameWithOutExtension", 33 | () => { 34 | currentFile.copyFileNameWithOutExtension(); 35 | }, 36 | ), 37 | commands.registerCommand("currentFilePath.openSettings", () => { 38 | currentFile.openSettings(); 39 | }), 40 | ]; 41 | 42 | disposableCommands.forEach((command) => { 43 | context.subscriptions.push(command); 44 | }); 45 | context.subscriptions.push(listner); 46 | context.subscriptions.push(currentFile); 47 | } 48 | 49 | export function deactivate() { 50 | // Nothing to do 51 | } 52 | -------------------------------------------------------------------------------- /src/quickPicker.ts: -------------------------------------------------------------------------------- 1 | import { QuickPickItem, window } from "vscode"; 2 | import { PathStyles, PathStartsFrom } from "./utils/types"; 3 | 4 | interface MenuQuickPickItem extends QuickPickItem { 5 | id: QuickPickerAction; 6 | } 7 | 8 | export enum QuickPickerAction { 9 | noAction, 10 | viewUnixStyle, 11 | viewWindowsStyle, 12 | viewFromSystemRoot, 13 | viewFromWorkSpaceRoot, 14 | copy, 15 | copyFileName, 16 | copyFileNameWithOutExtension, 17 | openSettings, 18 | } 19 | 20 | export class QuickPicker { 21 | private _pickItems: MenuQuickPickItem[] = []; 22 | 23 | constructor() { 24 | // Nothing to do 25 | } 26 | 27 | public async getActionId( 28 | currentStyle: string, 29 | isWorkSpace: boolean, 30 | pathStartsFrom: string, 31 | ): Promise { 32 | this._pickItems = []; 33 | 34 | if (currentStyle === PathStyles.UNIX) { 35 | this._pickItems.push({ 36 | id: QuickPickerAction.viewWindowsStyle, 37 | description: "", 38 | label: "Path separator: Windows style", 39 | detail: "View on Windows style path", 40 | }); 41 | } else { 42 | this._pickItems.push({ 43 | id: QuickPickerAction.viewUnixStyle, 44 | description: "", 45 | label: "Path separator: UNIX style", 46 | detail: "View on UNIX style path", 47 | }); 48 | } 49 | 50 | if (isWorkSpace) { 51 | if (pathStartsFrom === PathStartsFrom.WORK_SPACE) { 52 | this._pickItems.push({ 53 | id: QuickPickerAction.viewFromSystemRoot, 54 | description: "", 55 | label: "Path starts from: Root", 56 | detail: "View from root directory", 57 | }); 58 | } else { 59 | this._pickItems.push({ 60 | id: QuickPickerAction.viewFromWorkSpaceRoot, 61 | description: "", 62 | label: "Path starts from: WorkSpace", 63 | detail: "View from workspace highest directory", 64 | }); 65 | } 66 | } 67 | 68 | this._pickItems.push({ 69 | id: QuickPickerAction.copy, 70 | description: "Copy a current file path to clipboard.", 71 | label: "COPY: Path", 72 | }); 73 | 74 | this._pickItems.push({ 75 | id: QuickPickerAction.copyFileName, 76 | description: "Copy a current file name to clipboard.", 77 | label: "COPY: FileName", 78 | }); 79 | 80 | this._pickItems.push({ 81 | id: QuickPickerAction.copyFileNameWithOutExtension, 82 | description: "Copy a current file name (without extension) to clipboard.", 83 | label: "COPY: FileName without extension", 84 | }); 85 | 86 | this._pickItems.push({ 87 | id: QuickPickerAction.openSettings, 88 | label: "Settings: Open Extension Settings", 89 | }); 90 | 91 | const selectedAction = await window.showQuickPick(this._pickItems, { 92 | placeHolder: "Select", 93 | }); 94 | 95 | if (!selectedAction) { 96 | return QuickPickerAction.noAction; 97 | } 98 | 99 | return selectedAction.id; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/test/runLatestTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTests } from "@vscode/test-electron"; 3 | 4 | async function main() { 5 | const extensionDevelopmentPath = path.resolve(__dirname, "../../"); 6 | const extensionTestsPath = path.resolve(__dirname, "./suite/index"); 7 | 8 | // https://github.com/microsoft/vscode/issues/86382 9 | const tmpDir = path.resolve(__dirname, "..", "../testTmp"); 10 | 11 | // latest version test 12 | try { 13 | await runTests({ 14 | extensionDevelopmentPath, 15 | extensionTestsPath, 16 | launchArgs: ["--user-data-dir", tmpDir, "--disable-extensions"], 17 | }); 18 | } catch (err) { 19 | console.log(err); 20 | console.error("Failed to run tests"); 21 | process.exit(1); 22 | } 23 | } 24 | 25 | main(); 26 | -------------------------------------------------------------------------------- /src/test/runMinSupportVersionTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTests, downloadAndUnzipVSCode } from "@vscode/test-electron"; 3 | 4 | async function main() { 5 | const extensionDevelopmentPath = path.resolve(__dirname, "../../"); 6 | const extensionTestsPath = path.resolve(__dirname, "./suite/index"); 7 | 8 | // https://github.com/microsoft/vscode/issues/86382 9 | const tmpDir = path.resolve(__dirname, "..", "../testTmp"); 10 | 11 | // v1.70.0 test 12 | const vscodeExecutablePath = await downloadAndUnzipVSCode("1.70.0"); 13 | try { 14 | await runTests({ 15 | vscodeExecutablePath, 16 | extensionDevelopmentPath, 17 | extensionTestsPath, 18 | launchArgs: ["--user-data-dir", tmpDir, "--disable-extensions"], 19 | }); 20 | } catch (err) { 21 | console.log(err); 22 | console.error("Failed to run tests"); 23 | process.exit(1); 24 | } 25 | } 26 | 27 | main(); 28 | -------------------------------------------------------------------------------- /src/test/suite/extensions.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from "assert"; 2 | import * as path from "path"; 3 | import * as vscode from "vscode"; 4 | import { CurrentFile } from "../../currentFile"; 5 | const clipboard = vscode.env.clipboard; 6 | 7 | describe("Default config test", () => { 8 | before(async () => { 9 | const doc = await vscode.workspace.openTextDocument( 10 | path.resolve(__dirname, "../../../README.md"), 11 | ); 12 | await vscode.window.showTextDocument(doc); 13 | }); 14 | 15 | const config = vscode.workspace.getConfiguration("currentFilePath"); 16 | const currentFile = new CurrentFile(); 17 | 18 | it("defaultPathStyle setting is same with workSpace setting", async () => { 19 | //@ts-ignore 20 | // execute private method 21 | assert.strictEqual( 22 | config.get("defaultPathStyle"), 23 | //@ts-ignore 24 | currentFile.config.defaultPathStyle, 25 | ); 26 | }); 27 | 28 | it("priorityInStatusBar setting is same with workSpace setting", async () => { 29 | //@ts-ignore 30 | // execute private method 31 | assert.strictEqual( 32 | config.get("priorityInStatusBar"), 33 | //@ts-ignore 34 | currentFile.config.priorityInStatusBar, 35 | ); 36 | }); 37 | 38 | it("defaultPathStartsFrom setting is same with workSpace setting", async () => { 39 | //@ts-ignore 40 | // execute private method 41 | assert.strictEqual( 42 | config.get("defaultPathStartsFrom"), 43 | //@ts-ignore 44 | currentFile.config.defaultPathStartsFrom, 45 | ); 46 | }); 47 | }); 48 | 49 | describe("Copy features test", () => { 50 | before(async () => { 51 | const doc = await vscode.workspace.openTextDocument( 52 | path.resolve(__dirname, "../../../README.md"), 53 | ); 54 | await vscode.window.showTextDocument(doc); 55 | }); 56 | 57 | it("copy file path command should copy file path when in the workspace", async () => { 58 | vscode.commands.executeCommand("currentFilePath.copy").then(async () => { 59 | const text: any = await clipboard.readText(); 60 | console.log(await clipboard.readText()); 61 | // assert.strictEqual(text.startsWith(__dirname.replace(/\\/g, "/")), true); 62 | assert.strictEqual(text.endsWith("/README.md"), true); 63 | }); 64 | }); 65 | 66 | it("copy filename command should copy filename when in the workspace", async () => { 67 | await vscode.commands.executeCommand("currentFilePath.copyFileName"); 68 | assert.strictEqual(await clipboard.readText(), "README.md"); 69 | }); 70 | }); 71 | 72 | describe("Change path style featuer test", () => { 73 | before(async () => { 74 | const doc = await vscode.workspace.openTextDocument( 75 | path.resolve(__dirname, "../../../README.md"), 76 | ); 77 | await vscode.window.showTextDocument(doc); 78 | }); 79 | 80 | it("path style should be windows style: unix -> windows", async () => { 81 | await vscode.commands.executeCommand("currentFilePath.viewFromSystemRoot"); 82 | await vscode.commands.executeCommand("currentFilePath.copy"); 83 | const unixStyleString: string = await clipboard.readText(); 84 | assert.strictEqual( 85 | unixStyleString, 86 | path.join(__dirname, "../../../README.md").replace(/\\/g, "/"), 87 | ); 88 | 89 | await vscode.commands.executeCommand("currentFilePath.viewWindowsStyle"); 90 | await vscode.commands.executeCommand("currentFilePath.copy"); 91 | const winStyleString: string = await clipboard.readText(); 92 | assert.strictEqual( 93 | winStyleString, 94 | path.join(__dirname, "../../../README.md").replace(/\//g, "\\"), 95 | ); 96 | }); 97 | 98 | it("path style should be unix style: windows -> unix", async () => { 99 | await vscode.commands.executeCommand("currentFilePath.viewWindowsStyle"); 100 | await vscode.commands.executeCommand("currentFilePath.copy"); 101 | const winStyleString: string = await clipboard.readText(); 102 | assert.strictEqual( 103 | winStyleString, 104 | path.join(__dirname, "../../../README.md").replace(/\//g, "\\"), 105 | ); 106 | 107 | await vscode.commands.executeCommand("currentFilePath.viewUnixStyle"); 108 | await vscode.commands.executeCommand("currentFilePath.copy"); 109 | const unixStyleString: string = await clipboard.readText(); 110 | assert.strictEqual( 111 | unixStyleString, 112 | path.join(__dirname, "../../../README.md").replace(/\\/g, "/"), 113 | ); 114 | }); 115 | }); 116 | -------------------------------------------------------------------------------- /src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import * as Mocha from "mocha"; 3 | import { glob } from "glob"; 4 | 5 | export function run(): Promise { 6 | const mocha = new Mocha({ 7 | ui: "bdd", 8 | color: true, 9 | timeout: 10000, 10 | }); 11 | 12 | const testsRoot = path.resolve(__dirname, ".."); 13 | 14 | return new Promise((c, e) => { 15 | glob("**/**.test.js", { cwd: testsRoot }) 16 | .then((files) => { 17 | // Add files to the test suite 18 | files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); 19 | 20 | try { 21 | // Run the mocha test 22 | mocha.run((failures) => { 23 | if (failures > 0) { 24 | e(new Error(`${failures} tests failed.`)); 25 | } else { 26 | c(); 27 | } 28 | }); 29 | } catch (err) { 30 | console.error(err); 31 | e(err); 32 | } 33 | }) 34 | .catch((err) => { 35 | return e(err); 36 | }); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /src/utils/types.ts: -------------------------------------------------------------------------------- 1 | export const PathStyles = { 2 | UNIX: "unix", 3 | WINDOWS: "windows", 4 | }; 5 | 6 | export const PathStartsFrom = { 7 | ROOT_DIRECTORY: "rootDirectory", 8 | WORK_SPACE: "workSpace", 9 | }; 10 | -------------------------------------------------------------------------------- /testTmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoshinorin/vscode-current-file-path-extension/bc89516a623d9e4938c45c5bbf8d40d594ad23e2/testTmp/.gitkeep -------------------------------------------------------------------------------- /testTmp/README.md: -------------------------------------------------------------------------------- 1 | This is a workaround to solve issues related to testing on MacOS. It will output test data, so there's no need to commit it. 2 | 3 | > See: https://github.com/microsoft/vscode/issues/86382 4 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": [ 7 | "es6" 8 | ], 9 | "sourceMap": true, 10 | "baseUrl": ".", 11 | "strict": true, 12 | "strictNullChecks": true, 13 | "noUnusedLocals": true 14 | }, 15 | "include": [ 16 | "src", 17 | "test" 18 | ], 19 | "exclude": [ 20 | "node_modules", 21 | ".vscode-test" 22 | ] 23 | } 24 | --------------------------------------------------------------------------------