Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
06ba86f4
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,发现更多精彩内容 >>
提交
06ba86f4
编写于
3月 16, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
less code to care about for #18350
上级
98d826a2
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
21 addition
and
108 deletion
+21
-108
src/vs/base/common/paths.ts
src/vs/base/common/paths.ts
+0
-38
src/vs/base/test/common/paths.test.ts
src/vs/base/test/common/paths.test.ts
+0
-26
src/vs/code/electron-main/windows.ts
src/vs/code/electron-main/windows.ts
+10
-34
src/vs/code/node/windowsUtils.ts
src/vs/code/node/windowsUtils.ts
+2
-1
src/vs/workbench/parts/git/browser/views/changes/changesView.ts
.../workbench/parts/git/browser/views/changes/changesView.ts
+3
-2
src/vs/workbench/parts/git/browser/views/changes/changesViewer.ts
...orkbench/parts/git/browser/views/changes/changesViewer.ts
+2
-3
src/vs/workbench/services/keybinding/test/keyboardMapper.test.ts
...workbench/services/keybinding/test/keyboardMapper.test.ts
+1
-1
src/vs/workbench/test/workbenchTestServices.ts
src/vs/workbench/test/workbenchTestServices.ts
+3
-3
未找到文件。
src/vs/base/common/paths.ts
浏览文件 @
06ba86f4
...
...
@@ -319,44 +319,6 @@ export function makePosixAbsolute(path: string): string {
return
isPosixAbsolute
(
normalize
(
path
))
?
path
:
sep
+
path
;
}
export
function
isEqualOrParent
(
path
:
string
,
candidate
:
string
):
boolean
{
if
(
path
===
candidate
)
{
return
true
;
}
path
=
normalize
(
path
);
candidate
=
normalize
(
candidate
);
let
candidateLen
=
candidate
.
length
;
let
lastCandidateChar
=
candidate
.
charCodeAt
(
candidateLen
-
1
);
if
(
lastCandidateChar
===
CharCode
.
Slash
)
{
candidate
=
candidate
.
substring
(
0
,
candidateLen
-
1
);
candidateLen
-=
1
;
}
if
(
path
===
candidate
)
{
return
true
;
}
if
(
!
isLinux
)
{
// case insensitive
path
=
path
.
toLowerCase
();
candidate
=
candidate
.
toLowerCase
();
}
if
(
path
===
candidate
)
{
return
true
;
}
if
(
path
.
indexOf
(
candidate
)
!==
0
)
{
return
false
;
}
let
char
=
path
.
charCodeAt
(
candidateLen
);
return
char
===
CharCode
.
Slash
;
}
// Reference: https://en.wikipedia.org/wiki/Filename
const
INVALID_FILE_CHARS
=
isWindows
?
/
[\\/
:
\*\?
"<>
\|]
/g
:
/
[\\/]
/g
;
const
WINDOWS_FORBIDDEN_NAMES
=
/^
(
con|prn|aux|clock
\$
|nul|lpt
[
0-9
]
|com
[
0-9
])
$/i
;
...
...
src/vs/base/test/common/paths.test.ts
浏览文件 @
06ba86f4
...
...
@@ -169,32 +169,6 @@ suite('Paths', () => {
assert
.
equal
(
paths
.
join
(
'
http://localhost/test
'
,
'
test
'
),
'
http://localhost/test/test
'
);
});
test
(
'
isEqualOrParent
'
,
()
=>
{
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/
'
));
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo
'
));
assert
(
paths
.
isEqualOrParent
(
'
/
'
,
'
/
'
));
assert
(
paths
.
isEqualOrParent
(
'
/foo
'
,
'
/
'
));
assert
(
paths
.
isEqualOrParent
(
'
/foo
'
,
'
/foo/
'
));
assert
(
!
paths
.
isEqualOrParent
(
'
/foo
'
,
'
/f
'
));
assert
(
!
paths
.
isEqualOrParent
(
'
/foo
'
,
'
/foo/b
'
));
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/bar
'
));
assert
(
!
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
/foo/bar
'
));
assert
(
!
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/barr
'
));
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/xxx/../bar
'
));
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/./bar
'
));
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo
\\
bar
\\
'
));
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/bar/test.ts
'
));
assert
(
!
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/bar/test
'
));
assert
(
!
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/bar/test.
'
));
if
(
!
platform
.
isLinux
)
{
assert
(
paths
.
isEqualOrParent
(
'
/foo
'
,
'
/fOO/
'
));
assert
(
paths
.
isEqualOrParent
(
'
/fOO
'
,
'
/foo/
'
));
assert
(
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/BAR/test.ts
'
));
assert
(
!
paths
.
isEqualOrParent
(
'
foo/bar/test.ts
'
,
'
foo/BAR/test.
'
));
}
});
test
(
'
extname
'
,
()
=>
{
assert
.
equal
(
paths
.
extname
(
'
far.boo
'
),
'
.boo
'
);
assert
.
equal
(
paths
.
extname
(
'
far.b
'
),
'
.b
'
);
...
...
src/vs/code/electron-main/windows.ts
浏览文件 @
06ba86f4
...
...
@@ -9,7 +9,6 @@ import * as path from 'path';
import
*
as
fs
from
'
original-fs
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
*
as
types
from
'
vs/base/common/types
'
;
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
{
assign
,
mixin
}
from
'
vs/base/common/objects
'
;
...
...
@@ -31,6 +30,7 @@ import CommonEvent, { Emitter } from 'vs/base/common/event';
import
product
from
'
vs/platform/node/product
'
;
import
{
OpenContext
}
from
'
vs/code/common/windows
'
;
import
{
ITelemetryService
,
ITelemetryData
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
isParent
,
isEqual
}
from
'
vs/platform/files/common/files
'
;
enum
WindowError
{
UNRESPONSIVE
,
...
...
@@ -234,8 +234,8 @@ export class WindowsManager implements IWindowsMainService {
// Send to windows
if
(
target
)
{
const
otherWindowsWithTarget
=
WindowsManager
.
WINDOWS
.
filter
(
w
=>
w
.
id
!==
windowId
&&
typeof
w
.
openedWorkspacePath
===
'
string
'
);
const
directTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
this
.
isPath
Equal
(
target
,
w
.
openedWorkspacePath
));
const
parentTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
paths
.
isEqualOr
Parent
(
target
,
w
.
openedWorkspacePath
));
const
directTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
is
Equal
(
target
,
w
.
openedWorkspacePath
));
const
parentTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
is
Parent
(
target
,
w
.
openedWorkspacePath
));
const
targetWindow
=
directTargetMatch
.
length
?
directTargetMatch
[
0
]
:
parentTargetMatch
[
0
];
// prefer direct match over parent match
if
(
targetWindow
)
{
...
...
@@ -317,7 +317,7 @@ export class WindowsManager implements IWindowsMainService {
// Any non extension host window with same workspace
else
if
(
!
win
.
isExtensionDevelopmentHost
&&
!!
win
.
openedWorkspacePath
)
{
this
.
windowsState
.
openedFolders
.
forEach
(
o
=>
{
if
(
this
.
isPath
Equal
(
o
.
workspacePath
,
win
.
openedWorkspacePath
))
{
if
(
is
Equal
(
o
.
workspacePath
,
win
.
openedWorkspacePath
))
{
o
.
uiState
=
state
.
uiState
;
}
});
...
...
@@ -510,7 +510,7 @@ export class WindowsManager implements IWindowsMainService {
// Open remaining ones
allFoldersToOpen
.
forEach
(
folderToOpen
=>
{
if
(
windowsOnWorkspacePath
.
some
(
win
=>
this
.
isPath
Equal
(
win
.
openedWorkspacePath
,
folderToOpen
)))
{
if
(
windowsOnWorkspacePath
.
some
(
win
=>
is
Equal
(
win
.
openedWorkspacePath
,
folderToOpen
)))
{
return
;
// ignore folders that are already open
}
...
...
@@ -684,7 +684,7 @@ export class WindowsManager implements IWindowsMainService {
// Reload an existing extension development host window on the same path
// We currently do not allow more than one extension development window
// on the same extension path.
let
res
=
WindowsManager
.
WINDOWS
.
filter
(
w
=>
w
.
config
&&
this
.
isPath
Equal
(
w
.
config
.
extensionDevelopmentPath
,
openConfig
.
cli
.
extensionDevelopmentPath
));
let
res
=
WindowsManager
.
WINDOWS
.
filter
(
w
=>
w
.
config
&&
is
Equal
(
w
.
config
.
extensionDevelopmentPath
,
openConfig
.
cli
.
extensionDevelopmentPath
));
if
(
res
&&
res
.
length
===
1
)
{
this
.
reload
(
res
[
0
],
openConfig
.
cli
);
res
[
0
].
focus
();
// make sure it gets focus and is restored
...
...
@@ -906,7 +906,7 @@ export class WindowsManager implements IWindowsMainService {
// Known Folder - load from stored settings if any
if
(
configuration
.
workspacePath
)
{
const
stateForWorkspace
=
this
.
windowsState
.
openedFolders
.
filter
(
o
=>
this
.
isPath
Equal
(
o
.
workspacePath
,
configuration
.
workspacePath
)).
map
(
o
=>
o
.
uiState
);
const
stateForWorkspace
=
this
.
windowsState
.
openedFolders
.
filter
(
o
=>
is
Equal
(
o
.
workspacePath
,
configuration
.
workspacePath
)).
map
(
o
=>
o
.
uiState
);
if
(
stateForWorkspace
.
length
)
{
return
stateForWorkspace
[
0
];
}
...
...
@@ -1103,17 +1103,17 @@ export class WindowsManager implements IWindowsMainService {
const
res
=
windowsToTest
.
filter
(
w
=>
{
// match on workspace
if
(
typeof
w
.
openedWorkspacePath
===
'
string
'
&&
(
this
.
isPath
Equal
(
w
.
openedWorkspacePath
,
workspacePath
)))
{
if
(
typeof
w
.
openedWorkspacePath
===
'
string
'
&&
(
is
Equal
(
w
.
openedWorkspacePath
,
workspacePath
)))
{
return
true
;
}
// match on file
if
(
typeof
w
.
openedFilePath
===
'
string
'
&&
this
.
isPath
Equal
(
w
.
openedFilePath
,
filePath
))
{
if
(
typeof
w
.
openedFilePath
===
'
string
'
&&
is
Equal
(
w
.
openedFilePath
,
filePath
))
{
return
true
;
}
// match on file path
if
(
typeof
w
.
openedWorkspacePath
===
'
string
'
&&
filePath
&&
paths
.
isEqualOrParent
(
filePath
,
w
.
openedWorkspacePath
))
{
if
(
typeof
w
.
openedWorkspacePath
===
'
string
'
&&
filePath
&&
(
isEqual
(
filePath
,
w
.
openedWorkspacePath
)
||
isParent
(
filePath
,
w
.
openedWorkspacePath
)
))
{
return
true
;
}
...
...
@@ -1236,30 +1236,6 @@ export class WindowsManager implements IWindowsMainService {
this
.
_onWindowClose
.
fire
(
win
.
id
);
}
private
isPathEqual
(
pathA
:
string
,
pathB
:
string
):
boolean
{
if
(
pathA
===
pathB
)
{
return
true
;
}
if
(
!
pathA
||
!
pathB
)
{
return
false
;
}
pathA
=
path
.
normalize
(
pathA
);
pathB
=
path
.
normalize
(
pathB
);
if
(
pathA
===
pathB
)
{
return
true
;
}
if
(
!
platform
.
isLinux
)
{
pathA
=
pathA
.
toLowerCase
();
pathB
=
pathB
.
toLowerCase
();
}
return
pathA
===
pathB
;
}
public
updateWindowsJumpList
():
void
{
if
(
!
platform
.
isWindows
)
{
return
;
// only on windows
...
...
src/vs/code/node/windowsUtils.ts
浏览文件 @
06ba86f4
...
...
@@ -10,6 +10,7 @@ import * as fs from 'fs';
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
{
OpenContext
}
from
'
vs/code/common/windows
'
;
import
{
isParent
,
isEqual
}
from
'
vs/platform/files/common/files
'
;
/**
* Exported subset of VSCodeWindow for testing.
...
...
@@ -46,7 +47,7 @@ export function findBestWindowOrFolder<SimpleWindow extends ISimpleWindow>({ win
}
function
findBestWindow
<
WINDOW
extends
ISimpleWindow
>
(
windows
:
WINDOW
[],
filePath
:
string
):
WINDOW
{
const
containers
=
windows
.
filter
(
window
=>
typeof
window
.
openedWorkspacePath
===
'
string
'
&&
paths
.
isEqualOrParent
(
filePath
,
window
.
openedWorkspacePath
));
const
containers
=
windows
.
filter
(
window
=>
typeof
window
.
openedWorkspacePath
===
'
string
'
&&
(
isEqual
(
filePath
,
window
.
openedWorkspacePath
)
||
isParent
(
filePath
,
window
.
openedWorkspacePath
)
));
if
(
containers
.
length
)
{
return
containers
.
sort
((
a
,
b
)
=>
-
(
a
.
openedWorkspacePath
.
length
-
b
.
openedWorkspacePath
.
length
))[
0
];
}
...
...
src/vs/workbench/parts/git/browser/views/changes/changesView.ts
浏览文件 @
06ba86f4
...
...
@@ -39,6 +39,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
isParent
,
isEqual
}
from
'
vs/platform/files/common/files
'
;
import
IGitService
=
git
.
IGitService
;
...
...
@@ -452,12 +453,12 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
const
resource
=
WorkbenchEditorCommon
.
toResource
(
input
,
{
filter
:
'
file
'
});
if
(
resource
)
{
const
workspaceRoot
=
this
.
contextService
.
getWorkspace
().
resource
.
fsPath
;
if
(
!
workspaceRoot
||
!
paths
.
isEqualOr
Parent
(
resource
.
fsPath
,
workspaceRoot
))
{
if
(
!
workspaceRoot
||
!
isEqual
(
resource
.
fsPath
,
workspaceRoot
)
||
!
is
Parent
(
resource
.
fsPath
,
workspaceRoot
))
{
return
null
;
// out of workspace not yet supported
}
const
repositoryRoot
=
this
.
gitService
.
getModel
().
getRepositoryRoot
();
if
(
!
repositoryRoot
||
!
paths
.
isEqualOr
Parent
(
resource
.
fsPath
,
repositoryRoot
))
{
if
(
!
repositoryRoot
||
!
isEqual
(
resource
.
fsPath
,
repositoryRoot
)
||
!
is
Parent
(
resource
.
fsPath
,
repositoryRoot
))
{
return
null
;
// out of repository not supported
}
...
...
src/vs/workbench/parts/git/browser/views/changes/changesViewer.ts
浏览文件 @
06ba86f4
...
...
@@ -330,7 +330,6 @@ export class Renderer implements tree.IRenderer {
};
const
repositoryRoot
=
this
.
gitService
.
getModel
().
getRepositoryRoot
();
const
workspaceRoot
=
this
.
contextService
.
getWorkspace
().
resource
.
fsPath
;
const
status
=
fileStatus
.
getStatus
();
const
renamePath
=
fileStatus
.
getRename
();
...
...
@@ -344,7 +343,7 @@ export class Renderer implements tree.IRenderer {
data
.
status
.
title
=
Renderer
.
statusToTitle
(
status
);
const
resource
=
URI
.
file
(
paths
.
normalize
(
paths
.
join
(
repositoryRoot
,
path
)));
let
isInWorkspace
=
paths
.
isEqualOrParent
(
resource
.
fsPath
,
workspaceRoot
);
let
isInWorkspace
=
this
.
contextService
.
isInsideWorkspace
(
resource
);
let
rename
=
''
;
let
renameFolder
=
''
;
...
...
@@ -358,7 +357,7 @@ export class Renderer implements tree.IRenderer {
data
.
renameFolder
.
textContent
=
folder
;
const
resource
=
URI
.
file
(
paths
.
normalize
(
paths
.
join
(
repositoryRoot
,
renamePath
)));
isInWorkspace
=
paths
.
isEqualOrParent
(
resource
.
fsPath
,
workspaceRoot
);
isInWorkspace
=
this
.
contextService
.
isInsideWorkspace
(
resource
);
}
if
(
isInWorkspace
)
{
...
...
src/vs/workbench/services/keybinding/test/keyboardMapper.test.ts
浏览文件 @
06ba86f4
...
...
@@ -14,7 +14,7 @@ import { OperatingSystem } from 'vs/base/common/platform';
import
{
UserSettingsLabelProvider
,
PrintableKeypress
}
from
'
vs/platform/keybinding/common/keybindingLabels
'
;
import
{
USLayoutResolvedKeybinding
}
from
'
vs/platform/keybinding/common/abstractKeybindingService
'
;
import
{
KeyboardEventCodeUtils
,
KeyboardEventCode
}
from
'
vs/workbench/services/keybinding/common/keyboardEventCode
'
;
import
{
IHTMLContentElement
}
from
"
vs/base/common/htmlContent
"
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
function
_assertKeybindingTranslation
(
mapper
:
KeyboardMapper
,
OS
:
OperatingSystem
,
kb
:
number
,
expected
:
string
[]):
void
{
let
keybindingLabel
=
new
USLayoutResolvedKeybinding
(
createKeybinding
(
kb
),
OS
).
getUserSettingsLabel
();
...
...
src/vs/workbench/test/workbenchTestServices.ts
浏览文件 @
06ba86f4
...
...
@@ -34,7 +34,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
import
{
IEditorGroupService
,
GroupArrangement
,
GroupOrientation
,
ITabOptions
,
IMoveOptions
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
TextFileService
}
from
'
vs/workbench/services/textfile/common/textFileService
'
;
import
{
FileOperationEvent
,
IFileService
,
IResolveContentOptions
,
IFileOperationResult
,
IFileStat
,
IImportResult
,
FileChangesEvent
,
IResolveFileOptions
,
IContent
,
IUpdateContentOptions
,
IStreamContent
}
from
'
vs/platform/files/common/files
'
;
import
{
FileOperationEvent
,
IFileService
,
IResolveContentOptions
,
IFileOperationResult
,
IFileStat
,
IImportResult
,
FileChangesEvent
,
IResolveFileOptions
,
IContent
,
IUpdateContentOptions
,
IStreamContent
,
isEqual
,
isParent
}
from
'
vs/platform/files/common/files
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
ModeServiceImpl
}
from
'
vs/editor/common/services/modeServiceImpl
'
;
import
{
ModelServiceImpl
}
from
'
vs/editor/common/services/modelServiceImpl
'
;
...
...
@@ -52,7 +52,7 @@ import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IThemeService
,
ITheme
,
IThemingParticipant
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Color
}
from
"
vs/base/common/color
"
;
import
{
Color
}
from
'
vs/base/common/color
'
;
export
function
createFileInput
(
instantiationService
:
IInstantiationService
,
resource
:
URI
):
FileEditorInput
{
return
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
void
0
);
...
...
@@ -93,7 +93,7 @@ export class TestContextService implements IWorkspaceContextService {
public
isInsideWorkspace
(
resource
:
URI
):
boolean
{
if
(
resource
&&
this
.
workspace
)
{
return
paths
.
isEqualOr
Parent
(
resource
.
fsPath
,
this
.
workspace
.
resource
.
fsPath
);
return
isEqual
(
resource
.
fsPath
,
this
.
workspace
.
resource
.
fsPath
)
||
is
Parent
(
resource
.
fsPath
,
this
.
workspace
.
resource
.
fsPath
);
}
return
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录