Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fc0f2188
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fc0f2188
编写于
1月 12, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git: open change/file
上级
01001020
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
77 deletion
+90
-77
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+84
-8
extensions/git/src/main.ts
extensions/git/src/main.ts
+1
-1
extensions/git/src/scmProvider.ts
extensions/git/src/scmProvider.ts
+5
-68
未找到文件。
extensions/git/src/commands.ts
浏览文件 @
fc0f2188
...
...
@@ -7,13 +7,10 @@
import
{
Uri
,
commands
,
scm
,
Disposable
,
SCMResourceGroup
,
SCMResource
,
window
,
workspace
,
QuickPickItem
,
OutputChannel
}
from
'
vscode
'
;
import
{
IRef
,
RefType
}
from
'
./git
'
;
import
{
Model
,
Resource
}
from
'
./model
'
;
import
{
log
}
from
'
./util
'
;
import
{
Model
,
Resource
,
Status
}
from
'
./model
'
;
import
{
decorate
}
from
'
core-decorators
'
;
import
*
as
path
from
'
path
'
;
type
Command
=
(...
args
:
any
[])
=>
any
;
function
catchErrors
(
fn
:
(...
args
)
=>
Promise
<
any
>
):
(...
args
)
=>
void
{
return
(...
args
)
=>
fn
.
call
(
this
,
...
args
).
catch
(
async
err
=>
{
if
(
err
.
gitErrorCode
)
{
...
...
@@ -124,14 +121,93 @@ export class CommandCenter {
return
await
this
.
model
.
update
();
}
openChange
(
uri
:
Uri
):
void
{
@
decorate
(
catchErrors
)
async
openChange
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
log
(
'
open change
'
,
resource
);
if
(
!
resource
)
{
return
;
}
return
this
.
open
(
resource
);
}
async
open
(
resource
:
Resource
):
Promise
<
void
>
{
const
left
=
this
.
getLeftResource
(
resource
);
const
right
=
this
.
getRightResource
(
resource
);
const
title
=
this
.
getTitle
(
resource
);
if
(
!
left
)
{
if
(
!
right
)
{
// TODO
console
.
error
(
'
oh no
'
);
return
;
}
return
commands
.
executeCommand
<
void
>
(
'
vscode.open
'
,
right
);
}
return
commands
.
executeCommand
<
void
>
(
'
vscode.diff
'
,
left
,
right
,
title
);
}
private
getLeftResource
(
resource
:
Resource
):
Uri
|
undefined
{
switch
(
resource
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
case
Status
.
INDEX_RENAMED
:
return
resource
.
uri
.
with
({
scheme
:
'
git
'
,
query
:
'
HEAD
'
});
case
Status
.
MODIFIED
:
const
uriString
=
resource
.
uri
.
toString
();
const
[
indexStatus
]
=
this
.
model
.
indexGroup
.
resources
.
filter
(
r
=>
r
.
uri
.
toString
()
===
uriString
);
const
query
=
indexStatus
?
'
~
'
:
'
HEAD
'
;
return
resource
.
uri
.
with
({
scheme
:
'
git
'
,
query
});
}
}
openFile
(
uri
:
Uri
):
void
{
private
getRightResource
(
resource
:
Resource
):
Uri
|
undefined
{
switch
(
resource
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
case
Status
.
INDEX_ADDED
:
case
Status
.
INDEX_COPIED
:
case
Status
.
INDEX_RENAMED
:
return
resource
.
uri
.
with
({
scheme
:
'
git
'
});
case
Status
.
INDEX_DELETED
:
case
Status
.
DELETED
:
return
resource
.
uri
.
with
({
scheme
:
'
git
'
,
query
:
'
HEAD
'
});
case
Status
.
MODIFIED
:
case
Status
.
UNTRACKED
:
case
Status
.
IGNORED
:
case
Status
.
BOTH_MODIFIED
:
return
resource
.
uri
;
}
}
private
getTitle
(
resource
:
Resource
):
string
{
const
basename
=
path
.
basename
(
resource
.
uri
.
fsPath
);
switch
(
resource
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
case
Status
.
INDEX_RENAMED
:
return
`
${
basename
}
(Index)`
;
case
Status
.
MODIFIED
:
return
`
${
basename
}
(Working Tree)`
;
}
return
''
;
}
@
decorate
(
catchErrors
)
async
openFile
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
log
(
'
open file
'
,
resource
);
if
(
!
resource
)
{
return
;
}
return
commands
.
executeCommand
<
void
>
(
'
vscode.open
'
,
resource
.
uri
);
}
@
decorate
(
catchErrors
)
...
...
extensions/git/src/main.ts
浏览文件 @
fc0f2188
...
...
@@ -55,13 +55,13 @@ async function init(disposables: Disposable[]): Promise<void> {
const
repository
=
git
.
open
(
rootPath
);
const
repositoryRoot
=
await
repository
.
getRoot
();
const
model
=
new
Model
(
repositoryRoot
,
repository
);
const
provider
=
new
GitSCMProvider
(
model
);
const
outputChannel
=
window
.
createOutputChannel
(
'
git
'
);
outputChannel
.
appendLine
(
`Using git
${
info
.
version
}
from
${
info
.
path
}
`
);
git
.
onOutput
(
str
=>
outputChannel
.
append
(
str
),
null
,
disposables
);
const
commandCenter
=
new
CommandCenter
(
model
,
outputChannel
);
const
provider
=
new
GitSCMProvider
(
model
,
commandCenter
);
const
fsWatcher
=
workspace
.
createFileSystemWatcher
(
'
**
'
);
const
onWorkspaceChange
=
anyEvent
(
fsWatcher
.
onDidChange
,
fsWatcher
.
onDidCreate
,
fsWatcher
.
onDidDelete
);
...
...
extensions/git/src/scmProvider.ts
浏览文件 @
fc0f2188
...
...
@@ -5,9 +5,9 @@
'
use strict
'
;
import
{
scm
,
Uri
,
Disposable
,
SCMProvider
,
SCMResourceGroup
,
Event
,
commands
,
ProviderResult
}
from
'
vscode
'
;
import
{
Model
,
Status
,
Resource
,
ResourceGroup
}
from
'
./model
'
;
import
*
as
path
from
'
path
'
;
import
{
scm
,
Uri
,
Disposable
,
SCMProvider
,
SCMResourceGroup
,
Event
,
ProviderResult
}
from
'
vscode
'
;
import
{
Model
,
Resource
,
ResourceGroup
}
from
'
./model
'
;
import
{
CommandCenter
}
from
'
./commands
'
;
export
class
GitSCMProvider
implements
SCMProvider
{
...
...
@@ -17,7 +17,7 @@ export class GitSCMProvider implements SCMProvider {
get
onDidChange
():
Event
<
SCMResourceGroup
[]
>
{
return
this
.
model
.
onDidChange
;
}
get
label
():
string
{
return
'
Git
'
;
}
constructor
(
private
model
:
Model
)
{
constructor
(
private
model
:
Model
,
private
commandCenter
:
CommandCenter
)
{
model
.
update
();
scm
.
registerSCMProvider
(
'
git
'
,
this
);
}
...
...
@@ -29,70 +29,7 @@ export class GitSCMProvider implements SCMProvider {
}
open
(
resource
:
Resource
):
ProviderResult
<
void
>
{
const
left
=
this
.
getLeftResource
(
resource
);
const
right
=
this
.
getRightResource
(
resource
);
const
title
=
this
.
getTitle
(
resource
);
if
(
!
left
)
{
if
(
!
right
)
{
// TODO
console
.
error
(
'
oh no
'
);
return
;
}
return
commands
.
executeCommand
<
void
>
(
'
vscode.open
'
,
right
);
}
return
commands
.
executeCommand
<
void
>
(
'
vscode.diff
'
,
left
,
right
,
title
);
}
private
getLeftResource
(
resource
:
Resource
):
Uri
|
undefined
{
switch
(
resource
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
case
Status
.
INDEX_RENAMED
:
return
resource
.
uri
.
with
({
scheme
:
'
git
'
,
query
:
'
HEAD
'
});
case
Status
.
MODIFIED
:
const
uriString
=
resource
.
uri
.
toString
();
const
[
indexStatus
]
=
this
.
model
.
indexGroup
.
resources
.
filter
(
r
=>
r
.
uri
.
toString
()
===
uriString
);
const
query
=
indexStatus
?
'
~
'
:
'
HEAD
'
;
return
resource
.
uri
.
with
({
scheme
:
'
git
'
,
query
});
}
}
private
getRightResource
(
resource
:
Resource
):
Uri
|
undefined
{
switch
(
resource
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
case
Status
.
INDEX_ADDED
:
case
Status
.
INDEX_COPIED
:
case
Status
.
INDEX_RENAMED
:
return
resource
.
uri
.
with
({
scheme
:
'
git
'
});
case
Status
.
INDEX_DELETED
:
case
Status
.
DELETED
:
return
resource
.
uri
.
with
({
scheme
:
'
git
'
,
query
:
'
HEAD
'
});
case
Status
.
MODIFIED
:
case
Status
.
UNTRACKED
:
case
Status
.
IGNORED
:
case
Status
.
BOTH_MODIFIED
:
return
resource
.
uri
;
}
}
private
getTitle
(
resource
:
Resource
):
string
{
const
basename
=
path
.
basename
(
resource
.
uri
.
fsPath
);
switch
(
resource
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
case
Status
.
INDEX_RENAMED
:
return
`
${
basename
}
(Index)`
;
case
Status
.
MODIFIED
:
return
`
${
basename
}
(Working Tree)`
;
}
return
''
;
return
this
.
commandCenter
.
open
(
resource
);
}
drag
(
resource
:
Resource
,
resourceGroup
:
ResourceGroup
):
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录