@@ -12,8 +12,10 @@ import { VariableResolver, Variable, Text } from 'vs/editor/contrib/snippet/snip
1212import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry' ;
1313import { getLeadingWhitespace , commonPrefixLength , isFalsyOrWhitespace , pad , endsWith } from 'vs/base/common/strings' ;
1414import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
15- import { isSingleFolderWorkspaceIdentifier , toWorkspaceIdentifier , WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces' ;
15+ import { isSingleFolderWorkspaceIdentifier , toWorkspaceIdentifier , WORKSPACE_EXTENSION , IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces' ;
1616import { ILabelService } from 'vs/platform/label/common/label' ;
17+ import { normalizeDriveLetter } from 'vs/base/common/labels' ;
18+ import { URI } from 'vs/base/common/uri' ;
1719
1820export const KnownSnippetVariableNames : { [ key : string ] : true } = Object . freeze ( {
1921 'CURRENT_YEAR' : true ,
@@ -43,6 +45,7 @@ export const KnownSnippetVariableNames: { [key: string]: true } = Object.freeze(
4345 'BLOCK_COMMENT_END' : true ,
4446 'LINE_COMMENT' : true ,
4547 'WORKSPACE_NAME' : true ,
48+ 'WORKSPACE_FOLDER' : true ,
4649} ) ;
4750
4851export class CompositeSnippetVariableResolver implements VariableResolver {
@@ -272,7 +275,7 @@ export class WorkspaceBasedVariableResolver implements VariableResolver {
272275 }
273276
274277 resolve ( variable : Variable ) : string | undefined {
275- if ( variable . name !== 'WORKSPACE_NAME' || ! this . _workspaceService ) {
278+ if ( ! this . _workspaceService ) {
276279 return undefined ;
277280 }
278281
@@ -281,6 +284,15 @@ export class WorkspaceBasedVariableResolver implements VariableResolver {
281284 return undefined ;
282285 }
283286
287+ if ( variable . name === 'WORKSPACE_NAME' ) {
288+ return this . _resolveWorkspaceName ( workspaceIdentifier ) ;
289+ } else if ( variable . name === 'WORKSPACE_FOLDER' ) {
290+ return this . _resoveWorkspacePath ( workspaceIdentifier ) ;
291+ }
292+
293+ return undefined ;
294+ }
295+ private _resolveWorkspaceName ( workspaceIdentifier : IWorkspaceIdentifier | URI ) : string | undefined {
284296 if ( isSingleFolderWorkspaceIdentifier ( workspaceIdentifier ) ) {
285297 return path . basename ( workspaceIdentifier . path ) ;
286298 }
@@ -291,4 +303,16 @@ export class WorkspaceBasedVariableResolver implements VariableResolver {
291303 }
292304 return filename ;
293305 }
306+ private _resoveWorkspacePath ( workspaceIdentifier : IWorkspaceIdentifier | URI ) : string | undefined {
307+ if ( isSingleFolderWorkspaceIdentifier ( workspaceIdentifier ) ) {
308+ return normalizeDriveLetter ( workspaceIdentifier . fsPath ) ;
309+ }
310+
311+ let filename = path . basename ( workspaceIdentifier . configPath . path ) ;
312+ let folderpath = workspaceIdentifier . configPath . fsPath ;
313+ if ( endsWith ( folderpath , filename ) ) {
314+ folderpath = folderpath . substr ( 0 , folderpath . length - filename . length - 1 ) ;
315+ }
316+ return ( folderpath ? normalizeDriveLetter ( folderpath ) : '/' ) ;
317+ }
294318}
0 commit comments