mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Add support for documentRelativeDirName
and documentRelativeFilePath
(#200883)
Fixes #193752
This commit is contained in:
parent
a8811b33fe
commit
955ad8630b
|
@ -2,6 +2,7 @@
|
||||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
import * as path from 'path';
|
||||||
import * as picomatch from 'picomatch';
|
import * as picomatch from 'picomatch';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { Utils } from 'vscode-uri';
|
import { Utils } from 'vscode-uri';
|
||||||
|
@ -147,22 +148,26 @@ function resolveCopyDestinationSetting(documentUri: vscode.Uri, fileName: string
|
||||||
const workspaceFolder = getWorkspaceFolder(documentUri);
|
const workspaceFolder = getWorkspaceFolder(documentUri);
|
||||||
|
|
||||||
const vars = new Map<string, string>([
|
const vars = new Map<string, string>([
|
||||||
['documentDirName', documentDirName.path], // Parent directory path
|
// Document
|
||||||
|
['documentDirName', documentDirName.path], // Absolute parent directory path
|
||||||
|
['documentRelativeDirName', workspaceFolder ? path.posix.relative(workspaceFolder.path, documentDirName.path) : documentDirName.path], // Absolute parent directory path
|
||||||
['documentFileName', documentBaseName], // Full filename: file.md
|
['documentFileName', documentBaseName], // Full filename: file.md
|
||||||
['documentBaseName', documentBaseName.slice(0, documentBaseName.length - documentExtName.length)], // Just the name: file
|
['documentBaseName', documentBaseName.slice(0, documentBaseName.length - documentExtName.length)], // Just the name: file
|
||||||
['documentExtName', documentExtName.replace('.', '')], // Just the file ext: md
|
['documentExtName', documentExtName.replace('.', '')], // Just the file ext: md
|
||||||
|
['documentFilePath', documentUri.path], // Full document path
|
||||||
|
['documentRelativeFilePath', workspaceFolder ? path.posix.relative(workspaceFolder.path, documentUri.path) : documentUri.path], // Full document path relative to workspace
|
||||||
|
|
||||||
// Workspace
|
// Workspace
|
||||||
['documentWorkspaceFolder', (workspaceFolder ?? documentDirName).path],
|
['documentWorkspaceFolder', ((workspaceFolder ?? documentDirName).path)],
|
||||||
|
|
||||||
// File
|
// File
|
||||||
['fileName', fileName],// Full file name
|
['fileName', fileName], // Full file name
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return outDest.replaceAll(/\$\{(\w+)(?:\/([^\}]+?)\/([^\}]+?)\/)?\}/g, (_, name, pattern, replacement) => {
|
return outDest.replaceAll(/\$\{(\w+)(?:\/([^\}]+?)\/([^\}]+?)\/)?\}/g, (match, name, pattern, replacement) => {
|
||||||
const entry = vars.get(name);
|
const entry = vars.get(name);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return '';
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pattern && replacement) {
|
if (pattern && replacement) {
|
||||||
|
|
Loading…
Reference in a new issue