Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
9201da12
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
9201da12
编写于
3月 19, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Start moving typeConverters into namespaces
上级
c2d2b643
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
61 addition
and
56 deletion
+61
-56
extensions/typescript/src/features/baseCodeLensProvider.ts
extensions/typescript/src/features/baseCodeLensProvider.ts
+2
-2
extensions/typescript/src/features/completionItemProvider.ts
extensions/typescript/src/features/completionItemProvider.ts
+6
-6
extensions/typescript/src/features/definitionProviderBase.ts
extensions/typescript/src/features/definitionProviderBase.ts
+3
-3
extensions/typescript/src/features/documentHighlightProvider.ts
...ions/typescript/src/features/documentHighlightProvider.ts
+3
-3
extensions/typescript/src/features/documentSymbolProvider.ts
extensions/typescript/src/features/documentSymbolProvider.ts
+3
-3
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
-3
extensions/typescript/src/features/implementationsCodeLensProvider.ts
...ypescript/src/features/implementationsCodeLensProvider.ts
+3
-3
extensions/typescript/src/features/jsDocCompletionProvider.ts
...nsions/typescript/src/features/jsDocCompletionProvider.ts
+3
-3
extensions/typescript/src/features/quickFixProvider.ts
extensions/typescript/src/features/quickFixProvider.ts
+2
-2
extensions/typescript/src/features/refactorProvider.ts
extensions/typescript/src/features/refactorProvider.ts
+5
-5
extensions/typescript/src/features/referenceProvider.ts
extensions/typescript/src/features/referenceProvider.ts
+3
-3
extensions/typescript/src/features/referencesCodeLensProvider.ts
...ons/typescript/src/features/referencesCodeLensProvider.ts
+3
-3
extensions/typescript/src/features/renameProvider.ts
extensions/typescript/src/features/renameProvider.ts
+3
-3
extensions/typescript/src/features/signatureHelpProvider.ts
extensions/typescript/src/features/signatureHelpProvider.ts
+2
-2
extensions/typescript/src/features/workspaceSymbolProvider.ts
...nsions/typescript/src/features/workspaceSymbolProvider.ts
+2
-2
extensions/typescript/src/utils/typeConverters.ts
extensions/typescript/src/utils/typeConverters.ts
+10
-5
extensions/typescript/src/utils/workspaceEdit.ts
extensions/typescript/src/utils/workspaceEdit.ts
+3
-3
未找到文件。
extensions/typescript/src/features/baseCodeLensProvider.ts
浏览文件 @
9201da12
...
...
@@ -7,7 +7,7 @@ import { CodeLensProvider, CodeLens, CancellationToken, TextDocument, Range, Uri
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
{
escapeRegExp
}
from
'
../utils/regexp
'
;
export
class
ReferencesCodeLens
extends
CodeLens
{
...
...
@@ -136,7 +136,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider
return
null
;
}
const
range
=
t
sTextSpanToVsRange
(
span
);
const
range
=
t
ypeConverters
.
Range
.
fromTextSpan
(
span
);
const
text
=
document
.
getText
(
range
);
const
identifierMatch
=
new
RegExp
(
`^(.*?(\\b|\\W))
${
escapeRegExp
(
item
.
text
||
''
)}
(\\b|\\W)`
,
'
gm
'
);
...
...
extensions/typescript/src/features/completionItemProvider.ts
浏览文件 @
9201da12
...
...
@@ -11,7 +11,7 @@ import TypingsStatus from '../utils/typingsStatus';
import
*
as
Proto
from
'
../protocol
'
;
import
*
as
PConst
from
'
../protocol.const
'
;
import
*
as
Previewer
from
'
../utils/previewer
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
*
as
nls
from
'
vscode-nls
'
;
import
{
applyCodeAction
}
from
'
../utils/codeAction
'
;
...
...
@@ -51,14 +51,14 @@ class MyCompletionItem extends vscode.CompletionItem {
this
.
useCodeSnippet
=
useCodeSnippetsOnMethodSuggest
&&
(
this
.
kind
===
vscode
.
CompletionItemKind
.
Function
||
this
.
kind
===
vscode
.
CompletionItemKind
.
Method
);
if
(
tsEntry
.
replacementSpan
)
{
this
.
range
=
t
sTextSpanToVsRange
(
tsEntry
.
replacementSpan
);
this
.
range
=
t
ypeConverters
.
Range
.
fromTextSpan
(
tsEntry
.
replacementSpan
);
}
if
(
tsEntry
.
insertText
)
{
this
.
insertText
=
tsEntry
.
insertText
;
if
(
tsEntry
.
replacementSpan
)
{
this
.
range
=
t
sTextSpanToVsRange
(
tsEntry
.
replacementSpan
);
this
.
range
=
t
ypeConverters
.
Range
.
fromTextSpan
(
tsEntry
.
replacementSpan
);
if
(
this
.
insertText
[
0
]
===
'
[
'
)
{
// o.x -> o['x']
this
.
filterText
=
'
.
'
+
this
.
label
;
}
...
...
@@ -281,7 +281,7 @@ export default class TypeScriptCompletionItemProvider implements vscode.Completi
}
const
args
:
Proto
.
CompletionsRequestArgs
=
{
...
vsPositionToTsFileLocation
(
file
,
position
),
...
typeConverters
.
vsPositionToTsFileLocation
(
file
,
position
),
includeExternalModuleExports
:
completionConfiguration
.
autoImportSuggestions
,
includeInsertTextCompletions
:
true
};
...
...
@@ -330,7 +330,7 @@ export default class TypeScriptCompletionItemProvider implements vscode.Completi
item
.
resolve
();
const
args
:
Proto
.
CompletionDetailsRequestArgs
=
{
...
vsPositionToTsFileLocation
(
filepath
,
item
.
position
),
...
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
item
.
position
),
entryNames
:
[
item
.
tsEntry
.
source
?
{
name
:
item
.
tsEntry
.
name
,
source
:
item
.
tsEntry
.
source
}
:
item
.
tsEntry
.
name
]
...
...
@@ -495,7 +495,7 @@ export default class TypeScriptCompletionItemProvider implements vscode.Completi
// Workaround for https://github.com/Microsoft/TypeScript/issues/12677
// Don't complete function calls inside of destructive assigments or imports
try
{
const
infoResponse
=
await
this
.
client
.
execute
(
'
quickinfo
'
,
vsPositionToTsFileLocation
(
filepath
,
position
));
const
infoResponse
=
await
this
.
client
.
execute
(
'
quickinfo
'
,
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
position
));
const
info
=
infoResponse
.
body
;
switch
(
info
&&
info
.
kind
)
{
case
'
var
'
:
...
...
extensions/typescript/src/features/definitionProviderBase.ts
浏览文件 @
9201da12
...
...
@@ -7,7 +7,7 @@ import { TextDocument, Position, CancellationToken, Location } from 'vscode';
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
export
default
class
TypeScriptDefinitionProviderBase
{
constructor
(
...
...
@@ -25,7 +25,7 @@ export default class TypeScriptDefinitionProviderBase {
return
undefined
;
}
const
args
=
vsPositionToTsFileLocation
(
filepath
,
position
);
const
args
=
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
position
);
try
{
const
response
=
await
this
.
client
.
execute
(
definitionType
,
args
,
token
);
const
locations
:
Proto
.
FileSpan
[]
=
(
response
&&
response
.
body
)
||
[];
...
...
@@ -35,7 +35,7 @@ export default class TypeScriptDefinitionProviderBase {
return
locations
.
map
(
location
=>
{
const
resource
=
this
.
client
.
asUrl
(
location
.
file
);
return
resource
?
new
Location
(
resource
,
t
sTextSpanToVsRange
(
location
))
?
new
Location
(
resource
,
t
ypeConverters
.
Range
.
fromTextSpan
(
location
))
:
undefined
;
}).
filter
(
x
=>
x
)
as
Location
[];
}
catch
{
...
...
extensions/typescript/src/features/documentHighlightProvider.ts
浏览文件 @
9201da12
...
...
@@ -6,7 +6,7 @@
import
{
DocumentHighlightProvider
,
DocumentHighlight
,
DocumentHighlightKind
,
TextDocument
,
Position
,
Range
,
CancellationToken
}
from
'
vscode
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
const
stringDelimiters
=
[
'
"
'
,
'
\'
'
,
'
`
'
];
...
...
@@ -25,7 +25,7 @@ export default class TypeScriptDocumentHighlightProvider implements DocumentHigh
return
[];
}
const
args
=
vsPositionToTsFileLocation
(
filepath
,
position
);
const
args
=
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
position
);
try
{
const
response
=
await
this
.
client
.
execute
(
'
occurrences
'
,
args
,
token
);
const
data
=
response
.
body
;
...
...
@@ -42,7 +42,7 @@ export default class TypeScriptDocumentHighlightProvider implements DocumentHigh
}
return
data
.
map
(
item
=>
new
DocumentHighlight
(
t
sTextSpanToVsRange
(
item
),
t
ypeConverters
.
Range
.
fromTextSpan
(
item
),
item
.
isWriteAccess
?
DocumentHighlightKind
.
Write
:
DocumentHighlightKind
.
Read
));
}
return
[];
...
...
extensions/typescript/src/features/documentSymbolProvider.ts
浏览文件 @
9201da12
...
...
@@ -8,7 +8,7 @@ import { DocumentSymbolProvider, SymbolInformation, SymbolKind, TextDocument, Lo
import
*
as
Proto
from
'
../protocol
'
;
import
*
as
PConst
from
'
../protocol.const
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
const
outlineTypeTable
:
{
[
kind
:
string
]:
SymbolKind
}
=
Object
.
create
(
null
);
outlineTypeTable
[
PConst
.
Kind
.
module
]
=
SymbolKind
.
Module
;
...
...
@@ -71,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
,
t
sTextSpanToVsRange
(
item
.
spans
[
0
])));
new
Location
(
resource
,
t
ypeConverters
.
Range
.
fromTextSpan
(
item
.
spans
[
0
])));
foldingMap
[
key
]
=
result
;
bucket
.
push
(
result
);
}
...
...
@@ -86,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
,
t
sTextSpanToVsRange
(
item
.
spans
[
0
]))
new
Location
(
resource
,
t
ypeConverters
.
Range
.
fromTextSpan
(
item
.
spans
[
0
]))
);
if
(
item
.
childItems
&&
item
.
childItems
.
length
>
0
)
{
for
(
const
child
of
item
.
childItems
)
{
...
...
extensions/typescript/src/features/formattingProvider.ts
浏览文件 @
9201da12
...
...
@@ -7,7 +7,7 @@ import { DocumentRangeFormattingEditProvider, OnTypeFormattingEditProvider, Form
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
FormattingConfigurationManager
from
'
./formattingConfigurationManager
'
;
export
class
TypeScriptFormattingProvider
implements
DocumentRangeFormattingEditProvider
,
OnTypeFormattingEditProvider
{
...
...
@@ -116,7 +116,7 @@ export class TypeScriptFormattingProvider implements DocumentRangeFormattingEdit
}
private
codeEdit2SingleEditOperation
(
edit
:
Proto
.
CodeEdit
):
TextEdit
{
return
new
TextEdit
(
t
sTextSpanToVsRange
(
edit
),
edit
.
newText
);
return
new
TextEdit
(
t
ypeConverters
.
Range
.
fromTextSpan
(
edit
),
edit
.
newText
);
}
}
...
...
extensions/typescript/src/features/hoverProvider.ts
浏览文件 @
9201da12
...
...
@@ -8,7 +8,7 @@ import { HoverProvider, Hover, TextDocument, Position, CancellationToken } from
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tagsMarkdownPreview
}
from
'
../utils/previewer
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
export
default
class
TypeScriptHoverProvider
implements
HoverProvider
{
...
...
@@ -25,14 +25,14 @@ export default class TypeScriptHoverProvider implements HoverProvider {
if
(
!
filepath
)
{
return
undefined
;
}
const
args
=
vsPositionToTsFileLocation
(
filepath
,
position
);
const
args
=
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
position
);
try
{
const
response
=
await
this
.
client
.
execute
(
'
quickinfo
'
,
args
,
token
);
if
(
response
&&
response
.
body
)
{
const
data
=
response
.
body
;
return
new
Hover
(
TypeScriptHoverProvider
.
getContents
(
data
),
t
sTextSpanToVsRange
(
data
));
t
ypeConverters
.
Range
.
fromTextSpan
(
data
));
}
}
catch
(
e
)
{
// noop
...
...
extensions/typescript/src/features/implementationsCodeLensProvider.ts
浏览文件 @
9201da12
...
...
@@ -9,7 +9,7 @@ import * as PConst from '../protocol.const';
import
{
TypeScriptBaseCodeLensProvider
,
ReferencesCodeLens
,
CachedNavTreeResponse
}
from
'
./baseCodeLensProvider
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -37,7 +37,7 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
public
resolveCodeLens
(
inputCodeLens
:
CodeLens
,
token
:
CancellationToken
):
Promise
<
CodeLens
>
{
const
codeLens
=
inputCodeLens
as
ReferencesCodeLens
;
const
args
=
vsPositionToTsFileLocation
(
codeLens
.
file
,
codeLens
.
range
.
start
);
const
args
=
typeConverters
.
vsPositionToTsFileLocation
(
codeLens
.
file
,
codeLens
.
range
.
start
);
return
this
.
client
.
execute
(
'
implementation
'
,
args
,
token
).
then
(
response
=>
{
if
(
!
response
||
!
response
.
body
)
{
throw
codeLens
;
...
...
@@ -48,7 +48,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
?
t
sTextSpanToVsRange
(
reference
)
?
t
ypeConverters
.
Range
.
fromTextSpan
(
reference
)
:
new
Range
(
reference
.
start
.
line
-
1
,
reference
.
start
.
offset
-
1
,
reference
.
start
.
line
,
0
)))
...
...
extensions/typescript/src/features/jsDocCompletionProvider.ts
浏览文件 @
9201da12
...
...
@@ -9,7 +9,7 @@ import { ITypeScriptServiceClient } from '../typescriptService';
import
*
as
Proto
from
'
../protocol
'
;
import
*
as
nls
from
'
vscode-nls
'
;
import
{
vsPositionToTsFileLocation
,
tsTextSpanToVsRange
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
{
Command
,
CommandManager
}
from
'
../utils/commandManager
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -96,7 +96,7 @@ export default class JsDocCompletionProvider implements CompletionItemProvider {
if
(
!
tree
.
spans
.
length
)
{
return
false
;
}
const
span
=
t
sTextSpanToVsRange
(
tree
.
spans
[
0
]);
const
span
=
t
ypeConverters
.
Range
.
fromTextSpan
(
tree
.
spans
[
0
]);
if
(
position
.
line
===
span
.
start
.
line
-
1
||
position
.
line
===
span
.
start
.
line
)
{
return
true
;
}
...
...
@@ -162,7 +162,7 @@ class TryCompleteJsDocCommand implements Command {
}
public
static
getSnippetTemplate
(
client
:
ITypeScriptServiceClient
,
file
:
string
,
position
:
Position
):
Promise
<
SnippetString
|
undefined
>
{
const
args
=
vsPositionToTsFileLocation
(
file
,
position
);
const
args
=
typeConverters
.
vsPositionToTsFileLocation
(
file
,
position
);
return
Promise
.
race
([
client
.
execute
(
'
docCommentTemplate
'
,
args
),
new
Promise
<
Proto
.
DocCommandTemplateResponse
>
((
_
,
reject
)
=>
setTimeout
(
reject
,
250
))
...
...
extensions/typescript/src/features/quickFixProvider.ts
浏览文件 @
9201da12
...
...
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
vsRangeToTsFileRange
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
FormattingConfigurationManager
from
'
./formattingConfigurationManager
'
;
import
{
getEditForCodeAction
,
applyCodeActionCommands
}
from
'
../utils/codeAction
'
;
import
{
Command
,
CommandManager
}
from
'
../utils/commandManager
'
;
...
...
@@ -177,7 +177,7 @@ export default class TypeScriptQuickFixProvider implements vscode.CodeActionProv
token
:
vscode
.
CancellationToken
):
Promise
<
Iterable
<
vscode
.
CodeAction
>>
{
const
args
:
Proto
.
CodeFixRequestArgs
=
{
...
vsRangeToTsFileRange
(
file
,
diagnostic
.
range
),
...
typeConverters
.
vsRangeToTsFileRange
(
file
,
diagnostic
.
range
),
errorCodes
:
[
+
diagnostic
.
code
]
};
const
codeFixesResponse
=
await
this
.
client
.
execute
(
'
getCodeFixes
'
,
args
,
token
);
...
...
extensions/typescript/src/features/refactorProvider.ts
浏览文件 @
9201da12
...
...
@@ -9,7 +9,7 @@ import * as vscode from 'vscode';
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
,
vsRangeToTsFileRange
,
tsLocationToVsPosition
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
FormattingOptionsManager
from
'
./formattingConfigurationManager
'
;
import
{
CommandManager
,
Command
}
from
'
../utils/commandManager
'
;
...
...
@@ -32,7 +32,7 @@ class ApplyRefactoringCommand implements Command {
await
this
.
formattingOptionsManager
.
ensureFormatOptionsForDocument
(
document
,
undefined
);
const
args
:
Proto
.
GetEditsForRefactorRequestArgs
=
{
...
vsRangeToTsFileRange
(
file
,
range
),
...
typeConverters
.
vsRangeToTsFileRange
(
file
,
range
),
refactor
,
action
};
...
...
@@ -49,7 +49,7 @@ class ApplyRefactoringCommand implements Command {
const
renameLocation
=
response
.
body
.
renameLocation
;
if
(
renameLocation
)
{
if
(
vscode
.
window
.
activeTextEditor
&&
vscode
.
window
.
activeTextEditor
.
document
.
uri
.
fsPath
===
document
.
uri
.
fsPath
)
{
const
pos
=
tsLocationToVsPosition
(
renameLocation
);
const
pos
=
t
ypeConverters
.
t
sLocationToVsPosition
(
renameLocation
);
vscode
.
window
.
activeTextEditor
.
selection
=
new
vscode
.
Selection
(
pos
,
pos
);
await
vscode
.
commands
.
executeCommand
(
'
editor.action.rename
'
);
}
...
...
@@ -62,7 +62,7 @@ class ApplyRefactoringCommand implements Command {
for
(
const
edit
of
edits
)
{
for
(
const
textChange
of
edit
.
textChanges
)
{
workspaceEdit
.
replace
(
this
.
client
.
asUrl
(
edit
.
fileName
),
t
sTextSpanToVsRange
(
textChange
),
t
ypeConverters
.
Range
.
fromTextSpan
(
textChange
),
textChange
.
newText
);
}
}
...
...
@@ -137,7 +137,7 @@ export default class TypeScriptRefactorProvider implements vscode.CodeActionProv
}
const
range
=
editor
.
selection
;
const
args
:
Proto
.
GetApplicableRefactorsRequestArgs
=
vsRangeToTsFileRange
(
file
,
range
);
const
args
:
Proto
.
GetApplicableRefactorsRequestArgs
=
typeConverters
.
vsRangeToTsFileRange
(
file
,
range
);
try
{
const
response
=
await
this
.
client
.
execute
(
'
getApplicableRefactors
'
,
args
,
token
);
if
(
!
response
||
!
response
.
body
)
{
...
...
extensions/typescript/src/features/referenceProvider.ts
浏览文件 @
9201da12
...
...
@@ -6,7 +6,7 @@
import
{
ReferenceProvider
,
Location
,
TextDocument
,
Position
,
CancellationToken
}
from
'
vscode
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
export
default
class
TypeScriptReferenceSupport
implements
ReferenceProvider
{
public
constructor
(
...
...
@@ -23,7 +23,7 @@ export default class TypeScriptReferenceSupport implements ReferenceProvider {
return
[];
}
const
args
=
vsPositionToTsFileLocation
(
filepath
,
position
);
const
args
=
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
position
);
try
{
const
msg
=
await
this
.
client
.
execute
(
'
references
'
,
args
,
token
);
if
(
!
msg
.
body
)
{
...
...
@@ -36,7 +36,7 @@ export default class TypeScriptReferenceSupport implements ReferenceProvider {
continue
;
}
const
url
=
this
.
client
.
asUrl
(
ref
.
file
);
const
location
=
new
Location
(
url
,
t
sTextSpanToVsRange
(
ref
));
const
location
=
new
Location
(
url
,
t
ypeConverters
.
Range
.
fromTextSpan
(
ref
));
result
.
push
(
location
);
}
return
result
;
...
...
extensions/typescript/src/features/referencesCodeLensProvider.ts
浏览文件 @
9201da12
...
...
@@ -9,7 +9,7 @@ import * as PConst from '../protocol.const';
import
{
TypeScriptBaseCodeLensProvider
,
ReferencesCodeLens
,
CachedNavTreeResponse
}
from
'
./baseCodeLensProvider
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -37,7 +37,7 @@ export default class TypeScriptReferencesCodeLensProvider extends TypeScriptBase
public
resolveCodeLens
(
inputCodeLens
:
CodeLens
,
token
:
CancellationToken
):
Promise
<
CodeLens
>
{
const
codeLens
=
inputCodeLens
as
ReferencesCodeLens
;
const
args
=
vsPositionToTsFileLocation
(
codeLens
.
file
,
codeLens
.
range
.
start
);
const
args
=
typeConverters
.
vsPositionToTsFileLocation
(
codeLens
.
file
,
codeLens
.
range
.
start
);
return
this
.
client
.
execute
(
'
references
'
,
args
,
token
).
then
(
response
=>
{
if
(
!
response
||
!
response
.
body
)
{
throw
codeLens
;
...
...
@@ -45,7 +45,7 @@ export default class TypeScriptReferencesCodeLensProvider extends TypeScriptBase
const
locations
=
response
.
body
.
refs
.
map
(
reference
=>
new
Location
(
this
.
client
.
asUrl
(
reference
.
file
),
t
sTextSpanToVsRange
(
reference
)))
new
Location
(
this
.
client
.
asUrl
(
reference
.
file
),
t
ypeConverters
.
Range
.
fromTextSpan
(
reference
)))
.
filter
(
location
=>
// Exclude original definition from references
!
(
location
.
uri
.
toString
()
===
codeLens
.
document
.
toString
()
&&
...
...
extensions/typescript/src/features/renameProvider.ts
浏览文件 @
9201da12
...
...
@@ -7,7 +7,7 @@ import { RenameProvider, WorkspaceEdit, TextDocument, Position, CancellationToke
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
,
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
export
default
class
TypeScriptRenameProvider
implements
RenameProvider
{
public
constructor
(
...
...
@@ -25,7 +25,7 @@ export default class TypeScriptRenameProvider implements RenameProvider {
}
const
args
:
Proto
.
RenameRequestArgs
=
{
...
vsPositionToTsFileLocation
(
filepath
,
position
),
...
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
position
),
findInStrings
:
false
,
findInComments
:
false
};
...
...
@@ -48,7 +48,7 @@ export default class TypeScriptRenameProvider implements RenameProvider {
continue
;
}
for
(
const
textSpan
of
spanGroup
.
locs
)
{
result
.
replace
(
resource
,
t
sTextSpanToVsRange
(
textSpan
),
newName
);
result
.
replace
(
resource
,
t
ypeConverters
.
Range
.
fromTextSpan
(
textSpan
),
newName
);
}
}
return
result
;
...
...
extensions/typescript/src/features/signatureHelpProvider.ts
浏览文件 @
9201da12
...
...
@@ -8,7 +8,7 @@ import { SignatureHelpProvider, SignatureHelp, SignatureInformation, ParameterIn
import
*
as
Previewer
from
'
../utils/previewer
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
vsPositionToTsFileLocation
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
export
default
class
TypeScriptSignatureHelpProvider
implements
SignatureHelpProvider
{
...
...
@@ -21,7 +21,7 @@ export default class TypeScriptSignatureHelpProvider implements SignatureHelpPro
if
(
!
filepath
)
{
return
null
;
}
const
args
:
Proto
.
SignatureHelpRequestArgs
=
vsPositionToTsFileLocation
(
filepath
,
position
);
const
args
:
Proto
.
SignatureHelpRequestArgs
=
typeConverters
.
vsPositionToTsFileLocation
(
filepath
,
position
);
const
response
=
await
this
.
client
.
execute
(
'
signatureHelp
'
,
args
,
token
);
const
info
=
response
.
body
;
...
...
extensions/typescript/src/features/workspaceSymbolProvider.ts
浏览文件 @
9201da12
...
...
@@ -7,7 +7,7 @@ import { workspace, window, Uri, WorkspaceSymbolProvider, SymbolInformation, Sym
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
tsTextSpanToVsRange
}
from
'
../utils/typeConverters
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
function
getSymbolKind
(
item
:
Proto
.
NavtoItem
):
SymbolKind
{
switch
(
item
.
kind
)
{
...
...
@@ -71,7 +71,7 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
if
(
!
item
.
containerName
&&
item
.
kind
===
'
alias
'
)
{
continue
;
}
const
range
=
t
sTextSpanToVsRange
(
item
);
const
range
=
t
ypeConverters
.
Range
.
fromTextSpan
(
item
);
const
label
=
TypeScriptWorkspaceSymbolProvider
.
getLabel
(
item
);
result
.
push
(
new
SymbolInformation
(
label
,
getSymbolKind
(
item
),
item
.
containerName
||
''
,
new
Location
(
this
.
client
.
asUrl
(
item
.
file
),
range
)));
...
...
extensions/typescript/src/utils/typeConverters.ts
浏览文件 @
9201da12
...
...
@@ -3,14 +3,19 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Helpers for converting FROM vscode types TO ts types
*/
import
*
as
vscode
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
export
const
tsTextSpanToVsRange
=
(
span
:
Proto
.
TextSpan
)
=>
new
vscode
.
Range
(
span
.
start
.
line
-
1
,
span
.
start
.
offset
-
1
,
span
.
end
.
line
-
1
,
span
.
end
.
offset
-
1
);
export
namespace
Range
{
export
const
fromTextSpan
=
(
span
:
Proto
.
TextSpan
):
vscode
.
Range
=>
new
vscode
.
Range
(
span
.
start
.
line
-
1
,
span
.
start
.
offset
-
1
,
span
.
end
.
line
-
1
,
span
.
end
.
offset
-
1
);
}
export
const
tsLocationToVsPosition
=
(
tslocation
:
Proto
.
Location
)
=>
new
vscode
.
Position
(
tslocation
.
line
-
1
,
tslocation
.
offset
-
1
);
...
...
extensions/typescript/src/utils/workspaceEdit.ts
浏览文件 @
9201da12
...
...
@@ -5,7 +5,7 @@
import
*
as
vscode
from
'
vscode
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
tsTextSpanToVsRange
}
from
'
./typeConverters
'
;
import
*
as
typeConverters
from
'
./typeConverters
'
;
export
function
createWorkspaceEditFromFileCodeEdits
(
client
:
ITypeScriptServiceClient
,
...
...
@@ -15,7 +15,7 @@ export function createWorkspaceEditFromFileCodeEdits(
for
(
const
edit
of
edits
)
{
for
(
const
textChange
of
edit
.
textChanges
)
{
workspaceEdit
.
replace
(
client
.
asUrl
(
edit
.
fileName
),
t
sTextSpanToVsRange
(
textChange
),
t
ypeConverters
.
Range
.
fromTextSpan
(
textChange
),
textChange
.
newText
);
}
}
...
...
@@ -25,6 +25,6 @@ export function createWorkspaceEditFromFileCodeEdits(
export
function
tsCodeEditToVsTextEdit
(
edit
:
Proto
.
CodeEdit
):
vscode
.
TextEdit
{
return
new
vscode
.
TextEdit
(
t
sTextSpanToVsRange
(
edit
),
t
ypeConverters
.
Range
.
fromTextSpan
(
edit
),
edit
.
newText
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录