Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beerui/vscode-code-review
https://github.com/beerui/vscode-code-review
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/beerui/vscode-code-review
- Owner: beerui
- Created: 2024-11-29T01:47:03.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-12-02T12:04:41.000Z (27 days ago)
- Last Synced: 2024-12-02T13:22:04.905Z (27 days ago)
- Language: TypeScript
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
const vscode = require('vscode');
function getRelativePath() {
// 获取当前活动的编辑器
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('没有打开任何文件');
return;
}// 获取当前文件的完整路径
const filePath = editor.document.uri.fsPath;// 获取工作区的根目录
const workspaceFolder = vscode.workspace.getWorkspaceFolder(editor.document.uri);
if (!workspaceFolder) {
vscode.window.showErrorMessage('当前文件不在任何工作区中');
return;
}// 计算相对路径
const relativePath = vscode.workspace.asRelativePath(filePath, false);// 显示结果
vscode.window.showInformationMessage(`相对路径: ${relativePath}`);
return relativePath;
}module.exports = {
getRelativePath
};