Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9b363e8e
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,发现更多精彩内容 >>
提交
9b363e8e
编写于
3月 02, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup rename-flow, #7340
上级
78a2f08d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
107 deletion
+62
-107
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+1
-1
src/vs/editor/contrib/rename/rename.ts
src/vs/editor/contrib/rename/rename.ts
+60
-105
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+1
-1
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
9b363e8e
...
...
@@ -919,7 +919,7 @@ export interface WorkspaceEdit {
export
interface
RenameInformation
{
range
:
IRange
;
text
?
:
string
;
text
:
string
;
}
export
interface
RenameProvider
{
...
...
src/vs/editor/contrib/rename/rename.ts
浏览文件 @
9b363e8e
...
...
@@ -6,7 +6,7 @@
'
use strict
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
isPromiseCanceledError
,
illegalArgument
,
onUnexpectedExternalError
}
from
'
vs/base/common/errors
'
;
import
{
isPromiseCanceledError
,
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
{
KeyMod
,
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
...
...
@@ -22,8 +22,8 @@ import RenameInputField from './renameInputField';
import
{
ITextModelService
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
optional
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IThemeService
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
sequence
,
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
WorkspaceEdit
,
RenameProviderRegistry
,
RenameInformation
}
from
'
vs/editor/common/modes
'
;
import
{
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
WorkspaceEdit
,
RenameProviderRegistry
,
RenameInformation
,
RenameProvider
}
from
'
vs/editor/common/modes
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
alert
}
from
'
vs/base/browser/ui/aria/aria
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
...
...
@@ -32,69 +32,62 @@ import { EditorState, CodeEditorStateFlag } from 'vs/editor/browser/core/editorS
import
{
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
INotificationService
}
from
'
vs/platform/notification/common/notification
'
;
class
RenameSkeleton
{
export
function
rename
(
model
:
ITextModel
,
position
:
Position
,
newName
:
string
):
TPromise
<
WorkspaceEdit
>
{
private
_provider
:
RenameProvider
[];
const
supports
=
RenameProviderRegistry
.
ordered
(
model
);
const
rejects
:
string
[]
=
[];
let
hasResult
=
false
;
const
factory
=
supports
.
map
(
support
=>
{
return
():
TPromise
<
WorkspaceEdit
>
=>
{
if
(
!
hasResult
)
{
return
asWinJsPromise
((
token
)
=>
{
return
support
.
provideRenameEdits
(
model
,
position
,
newName
,
token
);
}).
then
(
result
=>
{
if
(
!
result
)
{
// ignore
}
else
if
(
!
result
.
rejectReason
)
{
hasResult
=
true
;
return
result
;
}
else
{
rejects
.
push
(
result
.
rejectReason
);
}
return
undefined
;
});
constructor
(
readonly
model
:
ITextModel
,
readonly
position
:
Position
)
{
this
.
_provider
=
RenameProviderRegistry
.
ordered
(
model
);
}
hasProvider
()
{
return
this
.
_provider
.
length
>
0
;
}
async
resolveRenameInformation
():
TPromise
<
RenameInformation
>
{
let
[
provider
]
=
this
.
_provider
;
let
information
:
RenameInformation
;
if
(
provider
.
resolveInitialRenameValue
)
{
information
=
await
asWinJsPromise
(
token
=>
provider
.
resolveInitialRenameValue
(
this
.
model
,
this
.
position
,
token
));
}
if
(
!
information
)
{
let
word
=
this
.
model
.
getWordAtPosition
(
this
.
position
);
if
(
word
)
{
information
=
{
range
:
new
Range
(
this
.
position
.
lineNumber
,
word
.
startColumn
,
this
.
position
.
lineNumber
,
word
.
endColumn
),
text
:
word
.
word
};
}
return
undefined
;
};
});
}
return
sequence
(
factory
).
then
((
values
):
WorkspaceEdit
=>
{
let
result
=
values
[
0
];
if
(
rejects
.
length
>
0
)
{
return
{
edits
:
undefined
,
rejectReason
:
rejects
.
join
(
'
\n
'
)
};
}
else
if
(
!
result
)
{
return
{
return
information
;
}
async
rename
(
newName
:
string
):
TPromise
<
WorkspaceEdit
>
{
let
[
provider
]
=
this
.
_provider
;
let
result
=
await
asWinJsPromise
((
token
)
=>
provider
.
provideRenameEdits
(
this
.
model
,
this
.
position
,
newName
,
token
));
if
(
!
result
)
{
result
=
{
edits
:
undefined
,
rejectReason
:
nls
.
localize
(
'
no result
'
,
"
No result.
"
)
};
}
else
{
return
result
;
}
});
return
result
;
}
}
// TODO@joh
// merge this into above function to make we always
// use the same provider for resolving and renamin
function
resolveInitialRenameValue
(
model
:
ITextModel
,
position
:
Position
):
TPromise
<
RenameInformation
>
{
const
[
first
]
=
RenameProviderRegistry
.
ordered
(
model
);
if
(
!
first
||
typeof
first
.
resolveInitialRenameValue
!==
'
function
'
)
{
return
TPromise
.
as
(
null
);
}
//Use first rename provider so that we always use the same for resolving the location and for the actual rename
return
asWinJsPromise
(
token
=>
first
.
resolveInitialRenameValue
(
model
,
position
,
token
)).
then
(
result
=>
{
return
!
result
?
undefined
:
result
;
},
err
=>
{
onUnexpectedExternalError
(
err
);
return
TPromise
.
wrapError
<
RenameInformation
>
(
new
Error
(
'
provider failed
'
));
});
export
function
rename
(
model
:
ITextModel
,
position
:
Position
,
newName
:
string
):
TPromise
<
WorkspaceEdit
>
{
return
new
RenameSkeleton
(
model
,
position
).
rename
(
newName
);
}
// --- register actions and commands
const
CONTEXT_RENAME_INPUT_VISIBLE
=
new
RawContextKey
<
boolean
>
(
'
renameInputVisible
'
,
false
);
...
...
@@ -132,70 +125,32 @@ class RenameController implements IEditorContribution {
}
public
async
run
():
TPromise
<
void
>
{
const
selection
=
this
.
editor
.
getSelection
();
let
lineNumber
=
selection
.
startLineNumber
,
selectionStart
=
0
,
selectionEnd
=
0
,
wordRange
:
Range
,
word
:
string
;
let
initialValue
=
await
resolveInitialRenameValue
(
this
.
editor
.
getModel
(),
this
.
editor
.
getPosition
());
if
(
initialValue
)
{
lineNumber
=
initialValue
.
range
.
startLineNumber
;
if
(
initialValue
.
text
)
{
word
=
initialValue
.
text
;
}
else
{
word
=
this
.
editor
.
getModel
().
getValueInRange
(
initialValue
.
range
);
}
selectionEnd
=
word
.
length
;
if
(
!
selection
.
isEmpty
()
&&
selection
.
startLineNumber
===
selection
.
endLineNumber
)
{
selectionStart
=
Math
.
max
(
0
,
selection
.
startColumn
-
initialValue
.
range
.
startColumn
);
selectionEnd
=
Math
.
min
(
initialValue
.
range
.
endColumn
,
selection
.
endColumn
)
-
initialValue
.
range
.
startColumn
;
}
wordRange
=
new
Range
(
lineNumber
,
initialValue
.
range
.
startColumn
,
lineNumber
,
initialValue
.
range
.
endColumn
);
const
skeleton
=
new
RenameSkeleton
(
this
.
editor
.
getModel
(),
this
.
editor
.
getPosition
());
let
initialValue
=
await
skeleton
.
resolveRenameInformation
();
if
(
!
initialValue
)
{
return
undefined
;
}
else
{
const
wordAtPosition
=
this
.
editor
.
getModel
().
getWordAtPosition
(
selection
.
getStartPosition
());
if
(
!
wordAtPosition
)
{
return
undefined
;
}
word
=
wordAtPosition
.
word
;
selectionEnd
=
word
.
length
;
if
(
!
selection
.
isEmpty
()
&&
selection
.
startLineNumber
===
selection
.
endLineNumber
)
{
selectionStart
=
Math
.
max
(
0
,
selection
.
startColumn
-
wordAtPosition
.
startColumn
);
selectionEnd
=
Math
.
min
(
wordAtPosition
.
endColumn
,
selection
.
endColumn
)
-
wordAtPosition
.
startColumn
;
}
let
selection
=
this
.
editor
.
getSelection
();
let
selectionStart
=
0
;
let
selectionEnd
=
initialValue
.
text
.
length
;
wordRange
=
new
Range
(
lineNumber
,
wordAtPosition
.
startColumn
,
lineNumber
,
wordAtPosition
.
endColumn
);
if
(
!
selection
.
isEmpty
()
&&
selection
.
startLineNumber
===
selection
.
endLineNumber
)
{
selectionStart
=
Math
.
max
(
0
,
selection
.
startColumn
-
initialValue
.
range
.
startColumn
);
selectionEnd
=
Math
.
min
(
initialValue
.
range
.
endColumn
,
selection
.
endColumn
)
-
initialValue
.
range
.
startColumn
;
}
this
.
_renameInputVisible
.
set
(
true
);
return
this
.
_renameInputField
.
getInput
(
wordRange
,
word
,
selectionStart
,
selectionEnd
).
then
(
newName
=>
{
return
this
.
_renameInputField
.
getInput
(
Range
.
lift
(
initialValue
.
range
),
initialValue
.
text
,
selectionStart
,
selectionEnd
).
then
(
newName
=>
{
this
.
_renameInputVisible
.
reset
();
this
.
editor
.
focus
();
const
edit
=
new
BulkEdit
(
this
.
editor
,
null
,
this
.
_textModelResolverService
,
this
.
_fileService
);
const
state
=
new
EditorState
(
this
.
editor
,
CodeEditorStateFlag
.
Position
|
CodeEditorStateFlag
.
Value
|
CodeEditorStateFlag
.
Selection
|
CodeEditorStateFlag
.
Scroll
);
const
renameOperation
=
rename
(
this
.
editor
.
getModel
(),
this
.
editor
.
getPosition
(),
newName
).
then
(
result
=>
{
const
renameOperation
=
skeleton
.
rename
(
newName
).
then
(
result
=>
{
if
(
result
.
rejectReason
)
{
if
(
state
.
validate
(
this
.
editor
))
{
MessageController
.
get
(
this
.
editor
).
showMessage
(
result
.
rejectReason
,
this
.
editor
.
getPosition
());
...
...
@@ -211,7 +166,7 @@ class RenameController implements IEditorContribution {
this
.
editor
.
setSelection
(
selection
);
}
// alert
alert
(
nls
.
localize
(
'
aria
'
,
"
Successfully renamed '{0}' to '{1}'. Summary: {2}
"
,
word
,
newName
,
edit
.
ariaMessage
()));
alert
(
nls
.
localize
(
'
aria
'
,
"
Successfully renamed '{0}' to '{1}'. Summary: {2}
"
,
initialValue
.
text
,
newName
,
edit
.
ariaMessage
()));
});
},
err
=>
{
...
...
src/vs/monaco.d.ts
浏览文件 @
9b363e8e
...
...
@@ -4966,7 +4966,7 @@ declare module monaco.languages {
export
interface
RenameInformation
{
range
:
IRange
;
text
?
:
string
;
text
:
string
;
}
export
interface
RenameProvider
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录