Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
474a29ee
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,发现更多精彩内容 >>
提交
474a29ee
编写于
9月 19, 2017
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace duplicated textSpan conversion logic
上级
ce3c4b3c
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
52 addition
and
44 deletion
+52
-44
extensions/typescript/src/features/baseCodeLensProvider.ts
extensions/typescript/src/features/baseCodeLensProvider.ts
+2
-4
extensions/typescript/src/features/codeActionProvider.ts
extensions/typescript/src/features/codeActionProvider.ts
+2
-3
extensions/typescript/src/features/completionItemProvider.ts
extensions/typescript/src/features/completionItemProvider.ts
+2
-1
extensions/typescript/src/features/definitionProviderBase.ts
extensions/typescript/src/features/definitionProviderBase.ts
+3
-2
extensions/typescript/src/features/documentHighlightProvider.ts
...ions/typescript/src/features/documentHighlightProvider.ts
+5
-4
extensions/typescript/src/features/documentSymbolProvider.ts
extensions/typescript/src/features/documentSymbolProvider.ts
+4
-6
extensions/typescript/src/features/formattingProvider.ts
extensions/typescript/src/features/formattingProvider.ts
+2
-2
extensions/typescript/src/features/hoverProvider.ts
extensions/typescript/src/features/hoverProvider.ts
+3
-2
extensions/typescript/src/features/implementationsCodeLensProvider.ts
...ypescript/src/features/implementationsCodeLensProvider.ts
+2
-3
extensions/typescript/src/features/refactorProvider.ts
extensions/typescript/src/features/refactorProvider.ts
+2
-3
extensions/typescript/src/features/referenceProvider.ts
extensions/typescript/src/features/referenceProvider.ts
+3
-4
extensions/typescript/src/features/referencesCodeLensProvider.ts
...ons/typescript/src/features/referencesCodeLensProvider.ts
+2
-4
extensions/typescript/src/features/renameProvider.ts
extensions/typescript/src/features/renameProvider.ts
+3
-4
extensions/typescript/src/features/workspaceSymbolProvider.ts
...nsions/typescript/src/features/workspaceSymbolProvider.ts
+3
-2
extensions/typescript/src/utils/convert.ts
extensions/typescript/src/utils/convert.ts
+14
-0
未找到文件。
extensions/typescript/src/features/baseCodeLensProvider.ts
浏览文件 @
474a29ee
...
...
@@ -7,6 +7,7 @@ import { CodeLensProvider, CodeLens, CancellationToken, TextDocument, Range, Uri
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
export
class
ReferencesCodeLens
extends
CodeLens
{
constructor
(
...
...
@@ -99,10 +100,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider
return
null
;
}
const
range
=
new
Range
(
span
.
start
.
line
-
1
,
span
.
start
.
offset
-
1
,
span
.
end
.
line
-
1
,
span
.
end
.
offset
-
1
);
const
range
=
textSpanToRange
(
span
);
const
text
=
document
.
getText
(
range
);
const
identifierMatch
=
new
RegExp
(
`^(.*?(\\b|\\W))
${(
item
.
text
||
''
).
replace
(
/
[
-[
\]
{}()*+?.,
\\
^$|#
\s]
/g
,
'
\\
$&
'
)}
(\\b|\\W)`
,
'
gm
'
);
...
...
extensions/typescript/src/features/codeActionProvider.ts
浏览文件 @
474a29ee
...
...
@@ -7,6 +7,7 @@ import { CodeActionProvider, TextDocument, Range, CancellationToken, CodeActionC
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
interface
NumberSet
{
[
key
:
number
]:
boolean
;
...
...
@@ -112,9 +113,7 @@ export default class TypeScriptCodeActionProvider implements CodeActionProvider
for
(
const
change
of
action
.
changes
)
{
for
(
const
textChange
of
change
.
textChanges
)
{
workspaceEdit
.
replace
(
this
.
client
.
asUrl
(
change
.
fileName
),
new
Range
(
textChange
.
start
.
line
-
1
,
textChange
.
start
.
offset
-
1
,
textChange
.
end
.
line
-
1
,
textChange
.
end
.
offset
-
1
),
textSpanToRange
(
textChange
),
textChange
.
newText
);
}
}
...
...
extensions/typescript/src/features/completionItemProvider.ts
浏览文件 @
474a29ee
...
...
@@ -11,6 +11,7 @@ import TypingsStatus from '../utils/typingsStatus';
import
*
as
PConst
from
'
../protocol.const
'
;
import
{
CompletionEntry
,
CompletionsRequestArgs
,
CompletionDetailsRequestArgs
,
CompletionEntryDetails
,
FileLocationRequestArgs
}
from
'
../protocol
'
;
import
*
as
Previewer
from
'
./previewer
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
import
*
as
nls
from
'
vscode-nls
'
;
let
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -32,7 +33,7 @@ class MyCompletionItem extends CompletionItem {
let
span
:
protocol
.
TextSpan
=
entry
.
replacementSpan
;
// The indexing for the range returned by the server uses 1-based indexing.
// We convert to 0-based indexing.
this
.
textEdit
=
TextEdit
.
replace
(
new
Range
(
span
.
start
.
line
-
1
,
span
.
start
.
offset
-
1
,
span
.
end
.
line
-
1
,
span
.
end
.
offset
-
1
),
entry
.
name
);
this
.
textEdit
=
TextEdit
.
replace
(
textSpanToRange
(
span
),
entry
.
name
);
}
else
{
// Try getting longer, prefix based range for completions that span words
const
wordRange
=
document
.
getWordRangeAtPosition
(
position
);
...
...
extensions/typescript/src/features/definitionProviderBase.ts
浏览文件 @
474a29ee
...
...
@@ -3,10 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
TextDocument
,
Position
,
Range
,
CancellationToken
,
Location
}
from
'
vscode
'
;
import
{
TextDocument
,
Position
,
CancellationToken
,
Location
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
export
default
class
TypeScriptDefinitionProviderBase
{
constructor
(
...
...
@@ -37,7 +38,7 @@ export default class TypeScriptDefinitionProviderBase {
if
(
resource
===
null
)
{
return
null
;
}
else
{
return
new
Location
(
resource
,
new
Range
(
location
.
start
.
line
-
1
,
location
.
start
.
offset
-
1
,
location
.
end
.
line
-
1
,
location
.
end
.
offset
-
1
));
return
new
Location
(
resource
,
textSpanToRange
(
location
));
}
}).
filter
(
x
=>
x
!==
null
)
as
Location
[];
},
()
=>
{
...
...
extensions/typescript/src/features/documentHighlightProvider.ts
浏览文件 @
474a29ee
...
...
@@ -7,6 +7,7 @@ import { DocumentHighlightProvider, DocumentHighlight, DocumentHighlightKind, Te
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
export
default
class
TypeScriptDocumentHighlightProvider
implements
DocumentHighlightProvider
{
...
...
@@ -37,10 +38,10 @@ export default class TypeScriptDocumentHighlightProvider implements DocumentHigh
return
[];
}
}
return
data
.
map
(
(
item
)
=>
{
return
new
DocumentHighlight
(
new
Range
(
item
.
start
.
line
-
1
,
item
.
start
.
offset
-
1
,
item
.
end
.
line
-
1
,
item
.
end
.
offset
-
1
),
item
.
isWriteAccess
?
DocumentHighlightKind
.
Write
:
DocumentHighlightKind
.
Read
);
}
);
return
data
.
map
(
item
=>
new
DocumentHighlight
(
textSpanToRange
(
item
),
item
.
isWriteAccess
?
DocumentHighlightKind
.
Write
:
DocumentHighlightKind
.
Read
)
);
}
return
[];
},
()
=>
{
...
...
extensions/typescript/src/features/documentSymbolProvider.ts
浏览文件 @
474a29ee
...
...
@@ -3,11 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
DocumentSymbolProvider
,
SymbolInformation
,
SymbolKind
,
TextDocument
,
Range
,
Location
,
CancellationToken
,
Uri
}
from
'
vscode
'
;
import
{
DocumentSymbolProvider
,
SymbolInformation
,
SymbolKind
,
TextDocument
,
Location
,
CancellationToken
,
Uri
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
*
as
PConst
from
'
../protocol.const
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
const
outlineTypeTable
:
{
[
kind
:
string
]:
SymbolKind
}
=
Object
.
create
(
null
);
outlineTypeTable
[
PConst
.
Kind
.
module
]
=
SymbolKind
.
Module
;
...
...
@@ -25,9 +26,6 @@ outlineTypeTable[PConst.Kind.variable] = SymbolKind.Variable;
outlineTypeTable
[
PConst
.
Kind
.
function
]
=
SymbolKind
.
Function
;
outlineTypeTable
[
PConst
.
Kind
.
localFunction
]
=
SymbolKind
.
Function
;
function
textSpan2Range
(
value
:
Proto
.
TextSpan
):
Range
{
return
new
Range
(
value
.
start
.
line
-
1
,
value
.
start
.
offset
-
1
,
value
.
end
.
line
-
1
,
value
.
end
.
offset
-
1
);
}
export
default
class
TypeScriptDocumentSymbolProvider
implements
DocumentSymbolProvider
{
public
constructor
(
...
...
@@ -73,7 +71,7 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
let
result
=
new
SymbolInformation
(
item
.
text
,
outlineTypeTable
[
item
.
kind
as
string
]
||
SymbolKind
.
Variable
,
containerLabel
?
containerLabel
:
''
,
new
Location
(
resource
,
textSpan
2
Range
(
item
.
spans
[
0
])));
new
Location
(
resource
,
textSpan
To
Range
(
item
.
spans
[
0
])));
foldingMap
[
key
]
=
result
;
bucket
.
push
(
result
);
}
...
...
@@ -88,7 +86,7 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
const
result
=
new
SymbolInformation
(
item
.
text
,
outlineTypeTable
[
item
.
kind
as
string
]
||
SymbolKind
.
Variable
,
containerLabel
?
containerLabel
:
''
,
new
Location
(
resource
,
textSpan
2
Range
(
item
.
spans
[
0
]))
new
Location
(
resource
,
textSpan
To
Range
(
item
.
spans
[
0
]))
);
if
(
item
.
childItems
&&
item
.
childItems
.
length
>
0
)
{
for
(
const
child
of
item
.
childItems
)
{
...
...
extensions/typescript/src/features/formattingProvider.ts
浏览文件 @
474a29ee
...
...
@@ -7,6 +7,7 @@ import { workspace as Workspace, DocumentRangeFormattingEditProvider, OnTypeForm
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
interface
Configuration
{
enable
:
boolean
;
...
...
@@ -205,8 +206,7 @@ export class TypeScriptFormattingProvider implements DocumentRangeFormattingEdit
}
private
codeEdit2SingleEditOperation
(
edit
:
Proto
.
CodeEdit
):
TextEdit
{
return
new
TextEdit
(
new
Range
(
edit
.
start
.
line
-
1
,
edit
.
start
.
offset
-
1
,
edit
.
end
.
line
-
1
,
edit
.
end
.
offset
-
1
),
edit
.
newText
);
return
new
TextEdit
(
textSpanToRange
(
edit
),
edit
.
newText
);
}
private
getFormatOptions
(
options
:
FormattingOptions
):
Proto
.
FormatCodeSettings
{
...
...
extensions/typescript/src/features/hoverProvider.ts
浏览文件 @
474a29ee
...
...
@@ -3,11 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
HoverProvider
,
Hover
,
TextDocument
,
Position
,
Range
,
CancellationToken
}
from
'
vscode
'
;
import
{
HoverProvider
,
Hover
,
TextDocument
,
Position
,
CancellationToken
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tagsMarkdownPreview
}
from
'
./previewer
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
export
default
class
TypeScriptHoverProvider
implements
HoverProvider
{
...
...
@@ -31,7 +32,7 @@ export default class TypeScriptHoverProvider implements HoverProvider {
const
data
=
response
.
body
;
return
new
Hover
(
TypeScriptHoverProvider
.
getContents
(
data
),
new
Range
(
data
.
start
.
line
-
1
,
data
.
start
.
offset
-
1
,
data
.
end
.
line
-
1
,
data
.
end
.
offset
-
1
));
textSpanToRange
(
data
));
}
}
catch
(
e
)
{
// noop
...
...
extensions/typescript/src/features/implementationsCodeLensProvider.ts
浏览文件 @
474a29ee
...
...
@@ -9,6 +9,7 @@ import * as PConst from '../protocol.const';
import
{
TypeScriptBaseCodeLensProvider
,
ReferencesCodeLens
}
from
'
./baseCodeLensProvider
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -50,9 +51,7 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
// Only take first line on implementation: https://github.com/Microsoft/vscode/issues/23924
new
Location
(
this
.
client
.
asUrl
(
reference
.
file
),
reference
.
start
.
line
===
reference
.
end
.
line
?
new
Range
(
reference
.
start
.
line
-
1
,
reference
.
start
.
offset
-
1
,
reference
.
end
.
line
-
1
,
reference
.
end
.
offset
-
1
)
?
textSpanToRange
(
reference
)
:
new
Range
(
reference
.
start
.
line
-
1
,
reference
.
start
.
offset
-
1
,
reference
.
start
.
line
,
0
)))
...
...
extensions/typescript/src/features/refactorProvider.ts
浏览文件 @
474a29ee
...
...
@@ -9,6 +9,7 @@ import { CodeActionProvider, TextDocument, Range, CancellationToken, CodeActionC
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
export
default
class
TypeScriptRefactorProvider
implements
CodeActionProvider
{
...
...
@@ -85,9 +86,7 @@ export default class TypeScriptRefactorProvider implements CodeActionProvider {
for
(
const
edit
of
edits
)
{
for
(
const
textChange
of
edit
.
textChanges
)
{
workspaceEdit
.
replace
(
this
.
client
.
asUrl
(
edit
.
fileName
),
new
Range
(
textChange
.
start
.
line
-
1
,
textChange
.
start
.
offset
-
1
,
textChange
.
end
.
line
-
1
,
textChange
.
end
.
offset
-
1
),
textSpanToRange
(
textChange
),
textChange
.
newText
);
}
}
...
...
extensions/typescript/src/features/referenceProvider.ts
浏览文件 @
474a29ee
...
...
@@ -3,10 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
ReferenceProvider
,
Location
,
TextDocument
,
Position
,
Range
,
CancellationToken
}
from
'
vscode
'
;
import
{
ReferenceProvider
,
Location
,
TextDocument
,
Position
,
CancellationToken
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
export
default
class
TypeScriptReferenceSupport
implements
ReferenceProvider
{
public
constructor
(
...
...
@@ -35,9 +36,7 @@ export default class TypeScriptReferenceSupport implements ReferenceProvider {
continue
;
}
const
url
=
this
.
client
.
asUrl
(
ref
.
file
);
const
location
=
new
Location
(
url
,
new
Range
(
ref
.
start
.
line
-
1
,
ref
.
start
.
offset
-
1
,
ref
.
end
.
line
-
1
,
ref
.
end
.
offset
-
1
));
const
location
=
new
Location
(
url
,
textSpanToRange
(
ref
));
result
.
push
(
location
);
}
return
result
;
...
...
extensions/typescript/src/features/referencesCodeLensProvider.ts
浏览文件 @
474a29ee
...
...
@@ -9,6 +9,7 @@ import * as PConst from '../protocol.const';
import
{
TypeScriptBaseCodeLensProvider
,
ReferencesCodeLens
}
from
'
./baseCodeLensProvider
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -47,10 +48,7 @@ export default class TypeScriptReferencesCodeLensProvider extends TypeScriptBase
const
locations
=
response
.
body
.
refs
.
map
(
reference
=>
new
Location
(
this
.
client
.
asUrl
(
reference
.
file
),
new
Range
(
reference
.
start
.
line
-
1
,
reference
.
start
.
offset
-
1
,
reference
.
end
.
line
-
1
,
reference
.
end
.
offset
-
1
)))
new
Location
(
this
.
client
.
asUrl
(
reference
.
file
),
textSpanToRange
(
reference
)))
.
filter
(
location
=>
// Exclude original definition from references
!
(
location
.
uri
.
fsPath
===
codeLens
.
document
.
fsPath
&&
...
...
extensions/typescript/src/features/renameProvider.ts
浏览文件 @
474a29ee
...
...
@@ -3,10 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
RenameProvider
,
WorkspaceEdit
,
TextDocument
,
Position
,
Range
,
CancellationToken
}
from
'
vscode
'
;
import
{
RenameProvider
,
WorkspaceEdit
,
TextDocument
,
Position
,
CancellationToken
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
export
default
class
TypeScriptRenameProvider
implements
RenameProvider
{
public
constructor
(
...
...
@@ -49,9 +50,7 @@ export default class TypeScriptRenameProvider implements RenameProvider {
continue
;
}
for
(
const
textSpan
of
spanGroup
.
locs
)
{
result
.
replace
(
resource
,
new
Range
(
textSpan
.
start
.
line
-
1
,
textSpan
.
start
.
offset
-
1
,
textSpan
.
end
.
line
-
1
,
textSpan
.
end
.
offset
-
1
),
newName
);
result
.
replace
(
resource
,
textSpanToRange
(
textSpan
),
newName
);
}
}
return
result
;
...
...
extensions/typescript/src/features/workspaceSymbolProvider.ts
浏览文件 @
474a29ee
...
...
@@ -3,10 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
workspace
,
window
,
Uri
,
WorkspaceSymbolProvider
,
SymbolInformation
,
SymbolKind
,
Range
,
Location
,
CancellationToken
}
from
'
vscode
'
;
import
{
workspace
,
window
,
Uri
,
WorkspaceSymbolProvider
,
SymbolInformation
,
SymbolKind
,
Location
,
CancellationToken
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypescriptServiceClient
}
from
'
../typescriptService
'
;
import
{
textSpanToRange
}
from
'
../utils/convert
'
;
function
getSymbolKind
(
item
:
Proto
.
NavtoItem
):
SymbolKind
{
switch
(
item
.
kind
)
{
...
...
@@ -67,7 +68,7 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
if
(
!
item
.
containerName
&&
item
.
kind
===
'
alias
'
)
{
continue
;
}
const
range
=
new
Range
(
item
.
start
.
line
-
1
,
item
.
start
.
offset
-
1
,
item
.
end
.
line
-
1
,
item
.
end
.
offset
-
1
);
const
range
=
textSpanToRange
(
item
);
let
label
=
item
.
name
;
if
(
item
.
kind
===
'
method
'
||
item
.
kind
===
'
function
'
)
{
label
+=
'
()
'
;
...
...
extensions/typescript/src/utils/convert.ts
0 → 100644
浏览文件 @
474a29ee
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Range
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
export
const
textSpanToRange
=
(
span
:
Proto
.
TextSpan
)
=>
new
Range
(
span
.
start
.
line
-
1
,
span
.
start
.
offset
-
1
,
span
.
end
.
line
-
1
,
span
.
end
.
offset
-
1
);
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录