Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
3ca51f6d
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,发现更多精彩内容 >>
提交
3ca51f6d
编写于
5月 19, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Convert IRenameSupport to RenameProvider
上级
30169da4
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
33 addition
and
98 deletion
+33
-98
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+6
-14
src/vs/editor/common/modes/supports.ts
src/vs/editor/common/modes/supports.ts
+0
-36
src/vs/editor/contrib/rename/browser/rename.ts
src/vs/editor/contrib/rename/browser/rename.ts
+3
-21
src/vs/editor/contrib/rename/common/rename.ts
src/vs/editor/contrib/rename/common/rename.ts
+11
-12
src/vs/workbench/api/node/extHostApiCommands.ts
src/vs/workbench/api/node/extHostApiCommands.ts
+1
-1
src/vs/workbench/api/node/extHostLanguageFeatures.ts
src/vs/workbench/api/node/extHostLanguageFeatures.ts
+9
-11
src/vs/workbench/test/node/api/extHostLanguageFeatures.test.ts
...s/workbench/test/node/api/extHostLanguageFeatures.test.ts
+3
-3
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
3ca51f6d
...
...
@@ -521,26 +521,18 @@ export interface IConfigurationSupport {
configure
(
options
:
any
):
TPromise
<
void
>
;
}
export
interface
IResourceEdit
{
resource
:
URI
;
range
?
:
editorCommon
.
IRange
;
range
:
editorCommon
.
IRange
;
newText
:
string
;
}
export
interface
IRenameResult
{
currentName
:
string
;
export
interface
WorkspaceEdit
{
edits
:
IResourceEdit
[];
rejectReason
?:
string
;
}
/**
* Interface used to support renaming of symbols
*/
export
interface
IRenameSupport
{
filter
?:
string
[];
rename
(
resource
:
URI
,
position
:
editorCommon
.
IPosition
,
newName
:
string
):
TPromise
<
IRenameResult
>
;
export
interface
RenameProvider
{
provideRenameEdits
(
model
:
editorCommon
.
IReadOnlyModel
,
position
:
editorCommon
.
IEditorPosition
,
newName
:
string
,
token
:
CancellationToken
):
WorkspaceEdit
|
Thenable
<
WorkspaceEdit
>
;
}
export
interface
ICommand
{
...
...
@@ -691,7 +683,7 @@ export interface IRichEditSupport {
export
const
ReferenceProviderRegistry
=
new
LanguageFeatureRegistry
<
ReferenceProvider
>
();
export
const
Rename
Registry
=
new
LanguageFeatureRegistry
<
IRenameSupport
>
();
export
const
Rename
ProviderRegistry
=
new
LanguageFeatureRegistry
<
RenameProvider
>
();
export
const
SuggestRegistry
=
new
LanguageFeatureRegistry
<
ISuggestSupport
>
();
...
...
src/vs/editor/common/modes/supports.ts
浏览文件 @
3ca51f6d
...
...
@@ -71,42 +71,6 @@ export function handleEvent<T>(context:modes.ILineContext, offset:number, runner
return
runner
(
nestedMode
,
newCtx
,
offset
-
firstTokenCharacterOffset
);
}
/**
* Returns {{true}} if the line token at the specified
* offset matches one of the provided types. Matching
* happens on a substring start from the end, unless
* anywhereInToken is set to true in which case matches
* happen on a substring at any position.
*/
export
function
isLineToken
(
context
:
modes
.
ILineContext
,
offset
:
number
,
types
:
string
[],
anywhereInToken
:
boolean
=
false
):
boolean
{
if
(
!
Array
.
isArray
(
types
)
||
types
.
length
===
0
)
{
return
false
;
}
if
(
context
.
getLineContent
().
length
<=
offset
)
{
return
false
;
}
var
tokenIdx
=
context
.
findIndexOfOffset
(
offset
);
var
type
=
context
.
getTokenType
(
tokenIdx
);
for
(
var
i
=
0
,
len
=
types
.
length
;
i
<
len
;
i
++
)
{
if
(
anywhereInToken
)
{
if
(
type
.
indexOf
(
types
[
i
])
>=
0
)
{
return
true
;
}
}
else
{
if
(
strings
.
endsWith
(
type
,
types
[
i
]))
{
return
true
;
}
}
}
return
false
;
}
export
class
FilteredLineContext
implements
modes
.
ILineContext
{
public
modeTransitions
:
ModeTransition
[];
...
...
src/vs/editor/contrib/rename/browser/rename.ts
浏览文件 @
3ca51f6d
...
...
@@ -18,8 +18,7 @@ import {EditorAction} from 'vs/editor/common/editorAction';
import
{
Behaviour
}
from
'
vs/editor/common/editorActionEnablement
'
;
import
{
IEditorActionDescriptorData
,
IRange
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CommonEditorRegistry
,
ContextKey
,
EditorActionDescriptor
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
isLineToken
}
from
'
vs/editor/common/modes/supports
'
;
import
{
RenameRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
RenameProviderRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
BulkEdit
,
createBulkEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
rename
}
from
'
../common/rename
'
;
...
...
@@ -58,28 +57,11 @@ export class RenameAction extends EditorAction {
}
public
isSupported
():
boolean
{
return
RenameRegistry
.
has
(
this
.
editor
.
getModel
())
&&
!
this
.
editor
.
getModel
().
hasEditableRange
()
&&
super
.
isSupported
();
return
Rename
Provider
Registry
.
has
(
this
.
editor
.
getModel
())
&&
!
this
.
editor
.
getModel
().
hasEditableRange
()
&&
super
.
isSupported
();
}
public
getEnablementState
():
boolean
{
let
model
=
this
.
editor
.
getModel
();
let
position
=
this
.
editor
.
getSelection
().
getStartPosition
();
let
lineContext
=
model
.
getLineContext
(
position
.
lineNumber
);
return
RenameRegistry
.
ordered
(
model
).
some
(
support
=>
{
if
(
!
support
.
filter
)
{
return
true
;
}
if
(
isLineToken
(
lineContext
,
position
.
column
-
1
,
support
.
filter
))
{
return
true
;
}
if
(
position
.
column
>
1
&&
isLineToken
(
lineContext
,
position
.
column
-
2
,
support
.
filter
))
{
// in case we are in between two tokens
return
true
;
}
});
return
RenameProviderRegistry
.
has
(
this
.
editor
.
getModel
());
}
public
run
(
event
?:
any
):
TPromise
<
any
>
{
...
...
src/vs/editor/contrib/rename/common/rename.ts
浏览文件 @
3ca51f6d
...
...
@@ -6,24 +6,25 @@
'
use strict
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
sequence
}
from
'
vs/base/common/async
'
;
import
{
sequence
,
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IReadOnlyModel
,
IPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IReadOnlyModel
,
I
Editor
Position
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
IRenameResult
,
Rename
Registry
}
from
'
vs/editor/common/modes
'
;
import
{
WorkspaceEdit
,
RenameProvider
Registry
}
from
'
vs/editor/common/modes
'
;
export
function
rename
(
model
:
IReadOnlyModel
,
position
:
I
Position
,
newName
:
string
):
TPromise
<
IRenameResul
t
>
{
export
function
rename
(
model
:
IReadOnlyModel
,
position
:
I
EditorPosition
,
newName
:
string
):
TPromise
<
WorkspaceEdi
t
>
{
const
supports
=
RenameRegistry
.
ordered
(
model
);
const
resource
=
model
.
getAssociatedResource
();
const
supports
=
RenameProviderRegistry
.
ordered
(
model
);
const
rejects
:
string
[]
=
[];
let
hasResult
=
false
;
const
factory
=
supports
.
map
(
support
=>
{
return
()
=>
{
if
(
!
hasResult
)
{
return
support
.
rename
(
resource
,
position
,
newName
).
then
(
result
=>
{
return
asWinJsPromise
((
token
)
=>
{
return
support
.
provideRenameEdits
(
model
,
position
,
newName
,
token
);
}).
then
(
result
=>
{
if
(
!
result
)
{
// ignore
}
else
if
(
!
result
.
rejectReason
)
{
...
...
@@ -37,17 +38,15 @@ export function rename(model: IReadOnlyModel, position: IPosition, newName: stri
};
});
return
sequence
(
factory
).
then
(
values
=>
{
return
sequence
(
factory
).
then
(
(
values
):
WorkspaceEdit
=>
{
let
result
=
values
[
0
];
if
(
rejects
.
length
>
0
)
{
return
<
IRenameResult
>
{
currentName
:
undefined
,
return
{
edits
:
undefined
,
rejectReason
:
rejects
.
join
(
'
\n
'
)
};
}
else
if
(
!
result
)
{
return
<
IRenameResult
>
{
currentName
:
undefined
,
return
{
edits
:
undefined
,
rejectReason
:
localize
(
'
no result
'
,
"
No result.
"
)
};
...
...
src/vs/workbench/api/node/extHostApiCommands.ts
浏览文件 @
3ca51f6d
...
...
@@ -285,7 +285,7 @@ class ExtHostApiCommands {
position
:
position
&&
typeConverters
.
fromPosition
(
position
),
newName
};
return
this
.
_commands
.
executeCommand
<
modes
.
IRenameResul
t
>
(
'
_executeDocumentRenameProvider
'
,
args
).
then
(
value
=>
{
return
this
.
_commands
.
executeCommand
<
modes
.
WorkspaceEdi
t
>
(
'
_executeDocumentRenameProvider
'
,
args
).
then
(
value
=>
{
if
(
!
value
)
{
return
;
}
...
...
src/vs/workbench/api/node/extHostLanguageFeatures.ts
浏览文件 @
3ca51f6d
...
...
@@ -415,7 +415,7 @@ class NavigateTypeAdapter implements INavigateTypesSupport {
}
}
class
RenameAdapter
implements
modes
.
IRenameSupport
{
class
RenameAdapter
{
private
_documents
:
ExtHostModelService
;
private
_provider
:
vscode
.
RenameProvider
;
...
...
@@ -425,7 +425,7 @@ class RenameAdapter implements modes.IRenameSupport {
this
.
_provider
=
provider
;
}
rename
(
resource
:
URI
,
position
:
IPosition
,
newName
:
string
):
TPromise
<
modes
.
IRenameResul
t
>
{
provideRenameEdits
(
resource
:
URI
,
position
:
IPosition
,
newName
:
string
):
TPromise
<
modes
.
WorkspaceEdi
t
>
{
let
doc
=
this
.
_documents
.
getDocumentData
(
resource
).
document
;
let
pos
=
TypeConverters
.
toPosition
(
position
);
...
...
@@ -436,8 +436,7 @@ class RenameAdapter implements modes.IRenameSupport {
return
;
}
let
result
=
<
modes
.
IRenameResult
>
{
currentName
:
undefined
,
let
result
=
<
modes
.
WorkspaceEdit
>
{
edits
:
[]
};
...
...
@@ -454,8 +453,7 @@ class RenameAdapter implements modes.IRenameSupport {
return
result
;
},
err
=>
{
if
(
typeof
err
===
'
string
'
)
{
return
<
modes
.
IRenameResult
>
{
currentName
:
undefined
,
return
<
modes
.
WorkspaceEdit
>
{
edits
:
undefined
,
rejectReason
:
err
};
...
...
@@ -792,8 +790,8 @@ export class ExtHostLanguageFeatures {
return
this
.
_createDisposable
(
handle
);
}
$
rename
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
newName
:
string
):
TPromise
<
modes
.
IRenameResul
t
>
{
return
this
.
_withAdapter
(
handle
,
RenameAdapter
,
adapter
=>
adapter
.
rename
(
resource
,
position
,
newName
));
$
provideRenameEdits
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
newName
:
string
):
TPromise
<
modes
.
WorkspaceEdi
t
>
{
return
this
.
_withAdapter
(
handle
,
RenameAdapter
,
adapter
=>
adapter
.
provideRenameEdits
(
resource
,
position
,
newName
));
}
// --- suggestion
...
...
@@ -975,9 +973,9 @@ export class MainThreadLanguageFeatures {
// --- rename
$registerRenameSupport
(
handle
:
number
,
selector
:
vscode
.
DocumentSelector
):
TPromise
<
any
>
{
this
.
_registrations
[
handle
]
=
modes
.
Rename
Registry
.
register
(
selector
,
<
modes
.
IRenameSupport
>
{
rename
:
(
resource
:
URI
,
position
:
IPosition
,
newName
:
string
):
TPromise
<
modes
.
IRenameResul
t
>
=>
{
return
this
.
_proxy
.
$rename
(
handle
,
resource
,
position
,
newName
);
this
.
_registrations
[
handle
]
=
modes
.
Rename
ProviderRegistry
.
register
(
selector
,
<
modes
.
RenameProvider
>
{
provideRenameEdits
:
(
model
:
IReadOnlyModel
,
position
:
IEditorPosition
,
newName
:
string
,
token
:
CancellationToken
):
Thenable
<
modes
.
WorkspaceEdi
t
>
=>
{
return
wireCancellationToken
(
token
,
this
.
_proxy
.
$provideRenameEdits
(
handle
,
model
.
getAssociatedResource
(),
position
,
newName
)
);
}
});
return
undefined
;
...
...
src/vs/workbench/test/node/api/extHostLanguageFeatures.test.ts
浏览文件 @
3ca51f6d
...
...
@@ -650,7 +650,7 @@ suite('ExtHostLanguageFeatures', function() {
return
threadService
.
sync
().
then
(()
=>
{
return
rename
(
model
,
{
lineNumber
:
1
,
column
:
1
}
,
'
newName
'
).
then
(
value
=>
{
return
rename
(
model
,
new
EditorPosition
(
1
,
1
)
,
'
newName
'
).
then
(
value
=>
{
throw
new
Error
(
''
);
},
err
=>
{
// expected
...
...
@@ -676,7 +676,7 @@ suite('ExtHostLanguageFeatures', function() {
return
threadService
.
sync
().
then
(()
=>
{
return
rename
(
model
,
{
lineNumber
:
1
,
column
:
1
}
,
'
newName
'
).
then
(
value
=>
{
return
rename
(
model
,
new
EditorPosition
(
1
,
1
)
,
'
newName
'
).
then
(
value
=>
{
assert
.
equal
(
value
.
edits
.
length
,
1
);
});
});
...
...
@@ -701,7 +701,7 @@ suite('ExtHostLanguageFeatures', function() {
return
threadService
.
sync
().
then
(()
=>
{
return
rename
(
model
,
{
lineNumber
:
1
,
column
:
1
}
,
'
newName
'
).
then
(
value
=>
{
return
rename
(
model
,
new
EditorPosition
(
1
,
1
)
,
'
newName
'
).
then
(
value
=>
{
assert
.
equal
(
value
.
edits
.
length
,
2
);
// least relevant renamer
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录