Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
1a0311ae
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1a0311ae
编写于
8月 23, 2018
作者:
I
isidor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
labelService: allow to register workspace label formater
上级
8f96ce69
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
67 addition
and
54 deletion
+67
-54
src/vs/code/electron-main/app.ts
src/vs/code/electron-main/app.ts
+1
-1
src/vs/editor/standalone/browser/simpleServices.ts
src/vs/editor/standalone/browser/simpleServices.ts
+4
-4
src/vs/platform/label/common/label.ts
src/vs/platform/label/common/label.ts
+33
-26
src/vs/platform/label/electron-browser/label.contribution.ts
src/vs/platform/label/electron-browser/label.contribution.ts
+1
-1
src/vs/platform/label/test/label.test.ts
src/vs/platform/label/test/label.test.ts
+14
-10
src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts
...vs/workbench/api/electron-browser/mainThreadFileSystem.ts
+3
-3
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+2
-2
src/vs/workbench/api/node/extHostFileSystem.ts
src/vs/workbench/api/node/extHostFileSystem.ts
+2
-2
src/vs/workbench/parts/files/electron-browser/files.contribution.ts
...kbench/parts/files/electron-browser/files.contribution.ts
+7
-5
未找到文件。
src/vs/code/electron-main/app.ts
浏览文件 @
1a0311ae
...
...
@@ -229,7 +229,7 @@ export class CodeApplication {
});
ipc
.
on
(
'
vscode:labelRegisterFormater
'
,
(
event
:
any
,
{
scheme
,
formater
})
=>
{
this
.
labelService
.
registerFormater
(
scheme
,
formater
);
this
.
labelService
.
registerFormat
t
er
(
scheme
,
formater
);
});
ipc
.
on
(
'
vscode:toggleDevTools
'
,
(
event
:
Event
)
=>
{
...
...
src/vs/editor/standalone/browser/simpleServices.ts
浏览文件 @
1a0311ae
...
...
@@ -45,7 +45,7 @@ import { WorkspaceEdit, isResourceTextEdit, TextEdit } from 'vs/editor/common/mo
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
ILabelService
,
Uri
LabelRules
}
from
'
vs/platform/label/common/label
'
;
import
{
ILabelService
,
LabelRules
}
from
'
vs/platform/label/common/label
'
;
export
class
SimpleModel
implements
ITextEditorModel
{
...
...
@@ -599,8 +599,8 @@ export class SimpleBulkEditService implements IBulkEditService {
export
class
SimpleUriLabelService
implements
ILabelService
{
_serviceBrand
:
any
;
private
readonly
_onDidRegisterFormat
er
:
Emitter
<
{
scheme
:
string
,
formater
:
UriLabelRules
}
>
=
new
Emitter
<
{
scheme
:
string
,
formater
:
Uri
LabelRules
}
>
();
public
readonly
onDidRegisterFormat
er
:
Event
<
{
scheme
:
string
,
formater
:
UriLabelRules
}
>
=
this
.
_onDidRegisterForma
ter
.
event
;
private
readonly
_onDidRegisterFormat
ter
:
Emitter
<
{
scheme
:
string
,
formatter
:
LabelRules
}
>
=
new
Emitter
<
{
scheme
:
string
,
formatter
:
LabelRules
}
>
();
public
readonly
onDidRegisterFormat
ter
:
Event
<
{
scheme
:
string
,
formatter
:
LabelRules
}
>
=
this
.
_onDidRegisterFormat
ter
.
event
;
public
getUriLabel
(
resource
:
URI
,
relative
?:
boolean
):
string
{
if
(
resource
.
scheme
===
'
file
'
)
{
...
...
@@ -613,7 +613,7 @@ export class SimpleUriLabelService implements ILabelService {
return
''
;
}
public
registerFormat
er
(
schema
:
string
,
formater
:
Uri
LabelRules
):
IDisposable
{
public
registerFormat
ter
(
schema
:
string
,
formatter
:
LabelRules
):
IDisposable
{
throw
new
Error
(
'
Not implemented
'
);
}
}
src/vs/platform/label/common/label.ts
浏览文件 @
1a0311ae
...
...
@@ -22,15 +22,20 @@ export interface ILabelService {
_serviceBrand
:
any
;
getUriLabel
(
resource
:
URI
,
relative
?:
boolean
,
forceNoTildify
?:
boolean
):
string
;
getWorkspaceLabel
(
workspace
:
(
IWorkspaceIdentifier
|
ISingleFolderWorkspaceIdentifier
|
IWorkspace
),
options
?:
{
verbose
:
boolean
}):
string
;
registerFormat
er
(
schema
:
string
,
formater
:
Uri
LabelRules
):
IDisposable
;
onDidRegisterFormat
er
:
Event
<
{
scheme
:
string
,
formater
:
Uri
LabelRules
}
>
;
registerFormat
ter
(
schema
:
string
,
formatter
:
LabelRules
):
IDisposable
;
onDidRegisterFormat
ter
:
Event
<
{
scheme
:
string
,
formatter
:
LabelRules
}
>
;
}
export
interface
UriLabelRules
{
label
:
string
;
// myLabel:/${path}
separator
:
'
/
'
|
'
\\
'
|
''
;
tildify
?:
boolean
;
normalizeDriveLetter
?:
boolean
;
export
interface
LabelRules
{
uri
:
{
label
:
string
;
// myLabel:/${path}
separator
:
'
/
'
|
'
\\
'
|
''
;
tildify
?:
boolean
;
normalizeDriveLetter
?:
boolean
;
};
workspace
?:
{
suffix
:
string
;
};
}
const
LABEL_SERVICE_ID
=
'
label
'
;
...
...
@@ -44,24 +49,24 @@ function hasDriveLetter(path: string): boolean {
export
class
LabelService
implements
ILabelService
{
_serviceBrand
:
any
;
private
readonly
format
ers
=
new
Map
<
string
,
Uri
LabelRules
>
();
private
readonly
_onDidRegisterFormat
er
=
new
Emitter
<
{
scheme
:
string
,
formater
:
Uri
LabelRules
}
>
();
private
readonly
format
ters
=
new
Map
<
string
,
LabelRules
>
();
private
readonly
_onDidRegisterFormat
ter
=
new
Emitter
<
{
scheme
:
string
,
formatter
:
LabelRules
}
>
();
constructor
(
@
IEnvironmentService
private
environmentService
:
IEnvironmentService
,
@
IWorkspaceContextService
private
contextService
:
IWorkspaceContextService
)
{
}
get
onDidRegisterFormat
er
():
Event
<
{
scheme
:
string
,
formater
:
Uri
LabelRules
}
>
{
return
this
.
_onDidRegisterFormater
.
event
;
get
onDidRegisterFormat
ter
():
Event
<
{
scheme
:
string
,
formatter
:
LabelRules
}
>
{
return
this
.
_onDidRegisterFormat
t
er
.
event
;
}
getUriLabel
(
resource
:
URI
,
relative
?:
boolean
,
forceNoTildify
?:
boolean
):
string
{
if
(
!
resource
)
{
return
undefined
;
}
const
format
er
=
this
.
forma
ters
.
get
(
resource
.
scheme
);
if
(
!
formater
)
{
const
format
ter
=
this
.
format
ters
.
get
(
resource
.
scheme
);
if
(
!
format
t
er
)
{
return
getPathLabel
(
resource
.
path
,
this
.
environmentService
,
relative
?
this
.
contextService
:
undefined
);
}
...
...
@@ -72,8 +77,8 @@ export class LabelService implements ILabelService {
if
(
isEqual
(
baseResource
.
uri
,
resource
,
!
isLinux
))
{
relativeLabel
=
''
;
// no label if resources are identical
}
else
{
const
baseResourceLabel
=
this
.
formatUri
(
baseResource
.
uri
,
formater
,
forceNoTildify
);
relativeLabel
=
ltrim
(
this
.
formatUri
(
resource
,
format
er
,
forceNoTildify
).
substring
(
baseResourceLabel
.
length
),
formater
.
separator
);
const
baseResourceLabel
=
this
.
formatUri
(
baseResource
.
uri
,
format
t
er
,
forceNoTildify
);
relativeLabel
=
ltrim
(
this
.
formatUri
(
resource
,
format
ter
,
forceNoTildify
).
substring
(
baseResourceLabel
.
length
),
formatter
.
uri
.
separator
);
}
const
hasMultipleRoots
=
this
.
contextService
.
getWorkspace
().
folders
.
length
>
1
;
...
...
@@ -86,7 +91,7 @@ export class LabelService implements ILabelService {
}
}
return
this
.
formatUri
(
resource
,
formater
,
forceNoTildify
);
return
this
.
formatUri
(
resource
,
format
t
er
,
forceNoTildify
);
}
getWorkspaceLabel
(
workspace
:
(
IWorkspaceIdentifier
|
ISingleFolderWorkspaceIdentifier
|
IWorkspace
),
options
?:
{
verbose
:
boolean
}):
string
{
...
...
@@ -100,7 +105,9 @@ export class LabelService implements ILabelService {
// Workspace: Single Folder
if
(
isSingleFolderWorkspaceIdentifier
(
workspace
))
{
// Folder on disk
return
options
&&
options
.
verbose
?
this
.
getUriLabel
(
workspace
)
:
basenameOrAuthority
(
workspace
);
const
formatter
=
this
.
formatters
.
get
(
workspace
.
scheme
);
const
label
=
options
&&
options
.
verbose
?
this
.
getUriLabel
(
workspace
)
:
basenameOrAuthority
(
workspace
);
return
formatter
&&
formatter
.
workspace
&&
formatter
.
workspace
.
suffix
?
`
${
label
}
(
${
formatter
.
workspace
.
suffix
}
)`
:
label
;
}
// Workspace: Untitled
...
...
@@ -118,17 +125,17 @@ export class LabelService implements ILabelService {
return
localize
(
'
workspaceName
'
,
"
{0} (Workspace)
"
,
workspaceName
);
}
registerFormat
er
(
scheme
:
string
,
formater
:
Uri
LabelRules
):
IDisposable
{
this
.
format
ers
.
set
(
scheme
,
forma
ter
);
this
.
_onDidRegisterFormat
er
.
fire
({
scheme
,
forma
ter
});
registerFormat
ter
(
scheme
:
string
,
formatter
:
LabelRules
):
IDisposable
{
this
.
format
ters
.
set
(
scheme
,
format
ter
);
this
.
_onDidRegisterFormat
ter
.
fire
({
scheme
,
format
ter
});
return
{
dispose
:
()
=>
this
.
formaters
.
delete
(
scheme
)
dispose
:
()
=>
this
.
format
t
ers
.
delete
(
scheme
)
};
}
private
formatUri
(
resource
:
URI
,
format
er
:
Uri
LabelRules
,
forceNoTildify
:
boolean
):
string
{
let
label
=
format
er
.
label
.
replace
(
labelMatchingRegexp
,
match
=>
{
private
formatUri
(
resource
:
URI
,
format
ter
:
LabelRules
,
forceNoTildify
:
boolean
):
string
{
let
label
=
format
ter
.
uri
.
label
.
replace
(
labelMatchingRegexp
,
match
=>
{
switch
(
match
)
{
case
'
${scheme}
'
:
return
resource
.
scheme
;
case
'
${authority}
'
:
return
resource
.
authority
;
...
...
@@ -138,15 +145,15 @@ export class LabelService implements ILabelService {
});
// convert \c:\something => C:\something
if
(
format
er
.
normalizeDriveLetter
&&
hasDriveLetter
(
label
))
{
if
(
format
ter
.
uri
.
normalizeDriveLetter
&&
hasDriveLetter
(
label
))
{
label
=
label
.
charAt
(
1
).
toUpperCase
()
+
label
.
substr
(
2
);
}
if
(
format
er
.
tildify
&&
!
forceNoTildify
)
{
if
(
format
ter
.
uri
.
tildify
&&
!
forceNoTildify
)
{
label
=
tildify
(
label
,
this
.
environmentService
.
userHome
);
}
return
label
.
replace
(
sepRegexp
,
format
er
.
separator
);
return
label
.
replace
(
sepRegexp
,
format
ter
.
uri
.
separator
);
}
}
...
...
src/vs/platform/label/electron-browser/label.contribution.ts
浏览文件 @
1a0311ae
...
...
@@ -16,7 +16,7 @@ import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
class
LabelRegistrationContribution
implements
IWorkbenchContribution
{
constructor
(@
ILabelService
labelService
:
ILabelService
)
{
labelService
.
onDidRegisterFormater
(
data
=>
{
labelService
.
onDidRegisterFormat
t
er
(
data
=>
{
ipc
.
send
(
'
vscode:labelRegisterFormater
'
,
data
);
});
}
...
...
src/vs/platform/label/test/
uriL
abel.test.ts
→
src/vs/platform/label/test/
l
abel.test.ts
浏览文件 @
1a0311ae
...
...
@@ -21,11 +21,13 @@ suite('URI Label', () => {
});
test
(
'
file scheme
'
,
function
()
{
labelService
.
registerFormater
(
Schemas
.
file
,
{
label
:
'
${path}
'
,
separator
:
nativeSep
,
tildify
:
!
isWindows
,
normalizeDriveLetter
:
isWindows
labelService
.
registerFormatter
(
Schemas
.
file
,
{
uri
:
{
label
:
'
${path}
'
,
separator
:
nativeSep
,
tildify
:
!
isWindows
,
normalizeDriveLetter
:
isWindows
}
});
const
uri1
=
TestWorkspace
.
folders
[
0
].
uri
.
with
({
path
:
TestWorkspace
.
folders
[
0
].
uri
.
path
.
concat
(
'
/a/b/c/d
'
)
});
...
...
@@ -37,11 +39,13 @@ suite('URI Label', () => {
});
test
(
'
custom scheme
'
,
function
()
{
labelService
.
registerFormater
(
Schemas
.
vscode
,
{
label
:
'
LABEL/${path}/${authority}/END
'
,
separator
:
'
/
'
,
tildify
:
true
,
normalizeDriveLetter
:
true
labelService
.
registerFormatter
(
Schemas
.
vscode
,
{
uri
:
{
label
:
'
LABEL/${path}/${authority}/END
'
,
separator
:
'
/
'
,
tildify
:
true
,
normalizeDriveLetter
:
true
}
});
const
uri1
=
URI
.
parse
(
'
vscode://microsoft.com/1/2/3/4/5
'
);
...
...
src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts
浏览文件 @
1a0311ae
...
...
@@ -11,7 +11,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
FileWriteOptions
,
FileSystemProviderCapabilities
,
IFileChange
,
IFileService
,
IFileSystemProvider
,
IStat
,
IWatchOptions
,
FileType
,
FileOverwriteOptions
,
FileDeleteOptions
}
from
'
vs/platform/files/common/files
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/electron-browser/extHostCustomers
'
;
import
{
ExtHostContext
,
ExtHostFileSystemShape
,
IExtHostContext
,
IFileChangeDto
,
MainContext
,
MainThreadFileSystemShape
}
from
'
../node/extHost.protocol
'
;
import
{
Uri
LabelRules
,
ILabelService
}
from
'
vs/platform/label/common/label
'
;
import
{
LabelRules
,
ILabelService
}
from
'
vs/platform/label/common/label
'
;
@
extHostNamedCustomer
(
MainContext
.
MainThreadFileSystem
)
export
class
MainThreadFileSystem
implements
MainThreadFileSystemShape
{
...
...
@@ -41,8 +41,8 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
this
.
_fileProvider
.
delete
(
handle
);
}
$setUriFormatter
(
scheme
:
string
,
formatter
:
Uri
LabelRules
):
void
{
this
.
_labelService
.
registerFormater
(
scheme
,
formatter
);
$setUriFormatter
(
scheme
:
string
,
formatter
:
LabelRules
):
void
{
this
.
_labelService
.
registerFormat
t
er
(
scheme
,
formatter
);
}
$onFileSystemChange
(
handle
:
number
,
changes
:
IFileChangeDto
[]):
void
{
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
1a0311ae
...
...
@@ -40,7 +40,7 @@ import { IExtensionDescription } from 'vs/workbench/services/extensions/common/e
import
{
createExtHostContextProxyIdentifier
as
createExtId
,
createMainContextProxyIdentifier
as
createMainId
,
IRPCProtocol
,
ProxyIdentifier
}
from
'
vs/workbench/services/extensions/node/proxyIdentifier
'
;
import
{
IProgressOptions
,
IProgressStep
}
from
'
vs/workbench/services/progress/common/progress
'
;
import
{
SaveReason
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
Uri
LabelRules
}
from
'
vs/platform/label/common/label
'
;
import
{
LabelRules
}
from
'
vs/platform/label/common/label
'
;
import
*
as
vscode
from
'
vscode
'
;
export
interface
IEnvironment
{
...
...
@@ -483,7 +483,7 @@ export interface IFileChangeDto {
export
interface
MainThreadFileSystemShape
extends
IDisposable
{
$registerFileSystemProvider
(
handle
:
number
,
scheme
:
string
,
capabilities
:
FileSystemProviderCapabilities
):
void
;
$unregisterProvider
(
handle
:
number
):
void
;
$setUriFormatter
(
scheme
:
string
,
formatter
:
Uri
LabelRules
):
void
;
$setUriFormatter
(
scheme
:
string
,
formatter
:
LabelRules
):
void
;
$onFileSystemChange
(
handle
:
number
,
resource
:
IFileChangeDto
[]):
void
;
}
...
...
src/vs/workbench/api/node/extHostFileSystem.ts
浏览文件 @
1a0311ae
...
...
@@ -15,7 +15,7 @@ import { values } from 'vs/base/common/map';
import
{
Range
,
FileChangeType
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
{
ExtHostLanguageFeatures
}
from
'
vs/workbench/api/node/extHostLanguageFeatures
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Uri
LabelRules
}
from
'
vs/platform/label/common/label
'
;
import
{
LabelRules
}
from
'
vs/platform/label/common/label
'
;
class
FsLinkProvider
implements
vscode
.
DocumentLinkProvider
{
...
...
@@ -142,7 +142,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
});
}
setUriFormatter
(
scheme
:
string
,
formatter
:
Uri
LabelRules
):
void
{
setUriFormatter
(
scheme
:
string
,
formatter
:
LabelRules
):
void
{
this
.
_proxy
.
$setUriFormatter
(
scheme
,
formatter
);
}
...
...
src/vs/workbench/parts/files/electron-browser/files.contribution.ts
浏览文件 @
1a0311ae
...
...
@@ -56,11 +56,13 @@ export class OpenExplorerViewletAction extends ToggleViewletAction {
class
FileUriLabelContribution
implements
IWorkbenchContribution
{
constructor
(@
ILabelService
labelService
:
ILabelService
)
{
labelService
.
registerFormater
(
Schemas
.
file
,
{
label
:
'
${path}
'
,
separator
:
nativeSep
,
tildify
:
!
platform
.
isWindows
,
normalizeDriveLetter
:
platform
.
isWindows
labelService
.
registerFormatter
(
Schemas
.
file
,
{
uri
:
{
label
:
'
${path}
'
,
separator
:
nativeSep
,
tildify
:
!
platform
.
isWindows
,
normalizeDriveLetter
:
platform
.
isWindows
}
});
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录