Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f7ed3485
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,发现更多精彩内容 >>
提交
f7ed3485
编写于
6月 03, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update JSON service to latest vscode-languageserver
上级
c843d585
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
60 addition
and
70 deletion
+60
-70
extensions/json/client/src/jsonMain.ts
extensions/json/client/src/jsonMain.ts
+1
-5
extensions/json/package.json
extensions/json/package.json
+1
-1
extensions/json/server/package.json
extensions/json/server/package.json
+1
-1
extensions/json/server/src/jsonCompletion.ts
extensions/json/server/src/jsonCompletion.ts
+11
-11
extensions/json/server/src/jsonDocumentSymbols.ts
extensions/json/server/src/jsonDocumentSymbols.ts
+2
-2
extensions/json/server/src/jsonFormatter.ts
extensions/json/server/src/jsonFormatter.ts
+4
-4
extensions/json/server/src/jsonHover.ts
extensions/json/server/src/jsonHover.ts
+8
-8
extensions/json/server/src/server.ts
extensions/json/server/src/server.ts
+15
-20
extensions/json/server/src/test/completion.test.ts
extensions/json/server/src/test/completion.test.ts
+6
-6
extensions/json/server/src/test/documentSymbols.test.ts
extensions/json/server/src/test/documentSymbols.test.ts
+2
-2
extensions/json/server/src/test/formatter.test.ts
extensions/json/server/src/test/formatter.test.ts
+4
-4
extensions/json/server/src/test/hover.test.ts
extensions/json/server/src/test/hover.test.ts
+3
-4
extensions/json/server/src/test/textEditSupport.ts
extensions/json/server/src/test/textEditSupport.ts
+2
-2
未找到文件。
extensions/json/client/src/jsonMain.ts
浏览文件 @
f7ed3485
...
...
@@ -10,10 +10,6 @@ import {workspace, languages, ExtensionContext, extensions, Uri} from 'vscode';
import
{
LanguageClient
,
LanguageClientOptions
,
RequestType
,
ServerOptions
,
TransportKind
,
NotificationType
}
from
'
vscode-languageclient
'
;
import
TelemetryReporter
from
'
vscode-extension-telemetry
'
;
namespace
TelemetryNotification
{
export
const
type
:
NotificationType
<
{
key
:
string
,
data
:
any
}
>
=
{
get
method
()
{
return
'
telemetry
'
;
}
};
}
namespace
VSCodeContentRequest
{
export
const
type
:
RequestType
<
string
,
string
,
any
>
=
{
get
method
()
{
return
'
vscode/content
'
;
}
};
}
...
...
@@ -68,7 +64,7 @@ export function activate(context: ExtensionContext) {
// Create the language client and start the client.
let
client
=
new
LanguageClient
(
'
JSON Server
'
,
serverOptions
,
clientOptions
);
client
.
on
Notification
(
TelemetryNotification
.
type
,
e
=>
{
client
.
on
Telemetry
(
e
=>
{
if
(
telemetryReporter
)
{
telemetryReporter
.
sendTelemetryEvent
(
e
.
key
,
e
.
data
);
}
...
...
extensions/json/package.json
浏览文件 @
f7ed3485
...
...
@@ -128,7 +128,7 @@
}
},
"dependencies"
:
{
"vscode-languageclient"
:
"^
1.3
.1"
,
"vscode-languageclient"
:
"^
2.2
.1"
,
"vscode-extension-telemetry"
:
"^0.0.5"
}
}
\ No newline at end of file
extensions/json/server/package.json
浏览文件 @
f7ed3485
...
...
@@ -10,7 +10,7 @@
"dependencies"
:
{
"request-light"
:
"^0.1.0"
,
"jsonc-parser"
:
"^0.2.0"
,
"vscode-languageserver"
:
"^
1.3
.0"
,
"vscode-languageserver"
:
"^
2.2
.0"
,
"vscode-nls"
:
"^1.0.4"
},
"scripts"
:
{
...
...
extensions/json/server/src/jsonCompletion.ts
浏览文件 @
f7ed3485
...
...
@@ -10,7 +10,7 @@ import SchemaService = require('./jsonSchemaService');
import
JsonSchema
=
require
(
'
./jsonSchema
'
);
import
{
IJSONWorkerContribution
}
from
'
./jsonContributions
'
;
import
{
CompletionItem
,
CompletionItemKind
,
CompletionList
,
ITextDocument
,
TextDocument
Position
,
Range
,
TextEdit
,
RemoteConsole
}
from
'
vscode-languageserver
'
;
import
{
CompletionItem
,
CompletionItemKind
,
CompletionList
,
TextDocument
,
Position
,
Range
,
TextEdit
,
RemoteConsole
}
from
'
vscode-languageserver
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -46,9 +46,9 @@ export class JSONCompletion {
return
Promise
.
resolve
(
item
);
}
public
doSuggest
(
document
:
ITextDocument
,
textDocumentPosition
:
TextDocument
Position
,
doc
:
Parser
.
JSONDocument
):
Thenable
<
CompletionList
>
{
public
doSuggest
(
document
:
TextDocument
,
position
:
Position
,
doc
:
Parser
.
JSONDocument
):
Thenable
<
CompletionList
>
{
let
offset
=
document
.
offsetAt
(
textDocumentPosition
.
position
);
let
offset
=
document
.
offsetAt
(
position
);
let
node
=
doc
.
getNodeFromOffsetEndInclusive
(
offset
);
let
currentWord
=
this
.
getCurrentWord
(
document
,
offset
);
...
...
@@ -61,7 +61,7 @@ export class JSONCompletion {
if
(
node
&&
(
node
.
type
===
'
string
'
||
node
.
type
===
'
number
'
||
node
.
type
===
'
boolean
'
||
node
.
type
===
'
null
'
))
{
overwriteRange
=
Range
.
create
(
document
.
positionAt
(
node
.
start
),
document
.
positionAt
(
node
.
end
));
}
else
{
overwriteRange
=
Range
.
create
(
document
.
positionAt
(
offset
-
currentWord
.
length
),
textDocumentPosition
.
position
);
overwriteRange
=
Range
.
create
(
document
.
positionAt
(
offset
-
currentWord
.
length
),
position
);
}
let
proposed
:
{
[
key
:
string
]:
boolean
}
=
{};
...
...
@@ -87,7 +87,7 @@ export class JSONCompletion {
}
};
return
this
.
schemaService
.
getSchemaForResource
(
textDocumentPosition
.
uri
,
doc
).
then
((
schema
)
=>
{
return
this
.
schemaService
.
getSchemaForResource
(
document
.
uri
,
doc
).
then
((
schema
)
=>
{
let
collectionPromises
:
Thenable
<
any
>
[]
=
[];
let
addValue
=
true
;
...
...
@@ -134,7 +134,7 @@ export class JSONCompletion {
let
location
=
node
.
getNodeLocation
();
this
.
contributions
.
forEach
((
contribution
)
=>
{
let
collectPromise
=
contribution
.
collectPropertySuggestions
(
textDocumentPosition
.
uri
,
location
,
currentWord
,
addValue
,
isLast
,
collector
);
let
collectPromise
=
contribution
.
collectPropertySuggestions
(
document
.
uri
,
location
,
currentWord
,
addValue
,
isLast
,
collector
);
if
(
collectPromise
)
{
collectionPromises
.
push
(
collectPromise
);
}
...
...
@@ -157,7 +157,7 @@ export class JSONCompletion {
if
(
!
node
)
{
this
.
contributions
.
forEach
((
contribution
)
=>
{
let
collectPromise
=
contribution
.
collectDefaultSuggestions
(
textDocumentPosition
.
uri
,
collector
);
let
collectPromise
=
contribution
.
collectDefaultSuggestions
(
document
.
uri
,
collector
);
if
(
collectPromise
)
{
collectionPromises
.
push
(
collectPromise
);
}
...
...
@@ -170,7 +170,7 @@ export class JSONCompletion {
if
(
!
valueNode
||
offset
<=
valueNode
.
end
)
{
let
location
=
node
.
parent
.
getNodeLocation
();
this
.
contributions
.
forEach
((
contribution
)
=>
{
let
collectPromise
=
contribution
.
collectValueSuggestions
(
textDocumentPosition
.
uri
,
location
,
parentKey
,
collector
);
let
collectPromise
=
contribution
.
collectValueSuggestions
(
document
.
uri
,
location
,
parentKey
,
collector
);
if
(
collectPromise
)
{
collectionPromises
.
push
(
collectPromise
);
}
...
...
@@ -230,7 +230,7 @@ export class JSONCompletion {
}
}
private
getSchemaLessValueSuggestions
(
doc
:
Parser
.
JSONDocument
,
node
:
Parser
.
ASTNode
,
offset
:
number
,
document
:
I
TextDocument
,
collector
:
ISuggestionsCollector
):
void
{
private
getSchemaLessValueSuggestions
(
doc
:
Parser
.
JSONDocument
,
node
:
Parser
.
ASTNode
,
offset
:
number
,
document
:
TextDocument
,
collector
:
ISuggestionsCollector
):
void
{
let
collectSuggestionsForValues
=
(
value
:
Parser
.
ASTNode
)
=>
{
if
(
!
value
.
contains
(
offset
))
{
let
content
=
this
.
getTextForMatchingNode
(
value
,
document
);
...
...
@@ -449,7 +449,7 @@ export class JSONCompletion {
}
private
getTextForMatchingNode
(
node
:
Parser
.
ASTNode
,
document
:
I
TextDocument
):
string
{
private
getTextForMatchingNode
(
node
:
Parser
.
ASTNode
,
document
:
TextDocument
):
string
{
switch
(
node
.
type
)
{
case
'
array
'
:
return
'
[]
'
;
...
...
@@ -513,7 +513,7 @@ export class JSONCompletion {
return
this
.
getTextForValue
(
key
);
}
private
getCurrentWord
(
document
:
I
TextDocument
,
offset
:
number
)
{
private
getCurrentWord
(
document
:
TextDocument
,
offset
:
number
)
{
var
i
=
offset
-
1
;
var
text
=
document
.
getText
();
while
(
i
>=
0
&&
'
\t\n\r\
v":{[,
'
.
indexOf
(
text
.
charAt
(
i
))
===
-
1
)
{
...
...
extensions/json/server/src/jsonDocumentSymbols.ts
浏览文件 @
f7ed3485
...
...
@@ -7,14 +7,14 @@
import
Parser
=
require
(
'
./jsonParser
'
);
import
Strings
=
require
(
'
./utils/strings
'
);
import
{
SymbolInformation
,
SymbolKind
,
I
TextDocument
,
Range
,
Location
}
from
'
vscode-languageserver
'
;
import
{
SymbolInformation
,
SymbolKind
,
TextDocument
,
Range
,
Location
}
from
'
vscode-languageserver
'
;
export
class
JSONDocumentSymbols
{
constructor
()
{
}
public
compute
(
document
:
I
TextDocument
,
doc
:
Parser
.
JSONDocument
):
Promise
<
SymbolInformation
[]
>
{
public
compute
(
document
:
TextDocument
,
doc
:
Parser
.
JSONDocument
):
Promise
<
SymbolInformation
[]
>
{
let
root
=
doc
.
root
;
if
(
!
root
)
{
...
...
extensions/json/server/src/jsonFormatter.ts
浏览文件 @
f7ed3485
...
...
@@ -5,9 +5,9 @@
'
use strict
'
;
import
Json
=
require
(
'
jsonc-parser
'
);
import
{
I
TextDocument
,
Range
,
Position
,
FormattingOptions
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
{
TextDocument
,
Range
,
Position
,
FormattingOptions
,
TextEdit
}
from
'
vscode-languageserver
'
;
export
function
format
(
document
:
I
TextDocument
,
range
:
Range
,
options
:
FormattingOptions
):
TextEdit
[]
{
export
function
format
(
document
:
TextDocument
,
range
:
Range
,
options
:
FormattingOptions
):
TextEdit
[]
{
const
documentText
=
document
.
getText
();
let
initialIndentLevel
:
number
;
let
value
:
string
;
...
...
@@ -83,7 +83,7 @@ export function format(document: ITextDocument, range: Range, options: Formattin
replaceContent
=
secondToken
===
Json
.
SyntaxKind
.
LineCommentTrivia
?
newLineAndIndent
()
:
''
;
secondToken
=
scanNext
();
}
if
(
secondToken
===
Json
.
SyntaxKind
.
CloseBraceToken
)
{
if
(
firstToken
!==
Json
.
SyntaxKind
.
OpenBraceToken
)
{
indentLevel
--
;
...
...
@@ -163,7 +163,7 @@ function computeIndentLevel(content: string, offset: number, options: Formatting
return
Math
.
floor
(
nChars
/
tabSize
);
}
function
getEOL
(
document
:
I
TextDocument
):
string
{
function
getEOL
(
document
:
TextDocument
):
string
{
let
text
=
document
.
getText
();
if
(
document
.
lineCount
>
1
)
{
let
to
=
document
.
offsetAt
(
Position
.
create
(
1
,
0
));
...
...
extensions/json/server/src/jsonHover.ts
浏览文件 @
f7ed3485
...
...
@@ -9,7 +9,7 @@ import Parser = require('./jsonParser');
import
SchemaService
=
require
(
'
./jsonSchemaService
'
);
import
{
IJSONWorkerContribution
}
from
'
./jsonContributions
'
;
import
{
Hover
,
ITextDocument
,
TextDocument
Position
,
Range
,
MarkedString
}
from
'
vscode-languageserver
'
;
import
{
Hover
,
TextDocument
,
Position
,
Range
,
MarkedString
}
from
'
vscode-languageserver
'
;
export
class
JSONHover
{
...
...
@@ -21,9 +21,9 @@ export class JSONHover {
this
.
contributions
=
contributions
;
}
public
doHover
(
document
:
ITextDocument
,
textDocumentPosition
:
TextDocument
Position
,
doc
:
Parser
.
JSONDocument
):
Thenable
<
Hover
>
{
public
doHover
(
document
:
TextDocument
,
position
:
Position
,
doc
:
Parser
.
JSONDocument
):
Thenable
<
Hover
>
{
let
offset
=
document
.
offsetAt
(
textDocumentPosition
.
position
);
let
offset
=
document
.
offsetAt
(
position
);
let
node
=
doc
.
getNodeFromOffset
(
offset
);
// use the property description when hovering over an object key
...
...
@@ -39,7 +39,7 @@ export class JSONHover {
if
(
!
node
)
{
return
Promise
.
resolve
(
void
0
);
}
var
createHover
=
(
contents
:
MarkedString
[])
=>
{
let
range
=
Range
.
create
(
document
.
positionAt
(
node
.
start
),
document
.
positionAt
(
node
.
end
));
let
result
:
Hover
=
{
...
...
@@ -47,18 +47,18 @@ export class JSONHover {
range
:
range
};
return
result
;
};
};
let
location
=
node
.
getNodeLocation
();
for
(
let
i
=
this
.
contributions
.
length
-
1
;
i
>=
0
;
i
--
)
{
let
contribution
=
this
.
contributions
[
i
];
let
promise
=
contribution
.
getInfoContribution
(
textDocumentPosition
.
uri
,
location
);
let
promise
=
contribution
.
getInfoContribution
(
document
.
uri
,
location
);
if
(
promise
)
{
return
promise
.
then
(
htmlContent
=>
createHover
(
htmlContent
));
}
}
return
this
.
schemaService
.
getSchemaForResource
(
textDocumentPosition
.
uri
,
doc
).
then
((
schema
)
=>
{
return
this
.
schemaService
.
getSchemaForResource
(
document
.
uri
,
doc
).
then
((
schema
)
=>
{
if
(
schema
)
{
let
matchingSchemas
:
Parser
.
IApplicableSchema
[]
=
[];
doc
.
validate
(
schema
.
schema
,
matchingSchemas
,
node
.
start
);
...
...
extensions/json/server/src/server.ts
浏览文件 @
f7ed3485
...
...
@@ -5,11 +5,10 @@
'
use strict
'
;
import
{
IPCMessageReader
,
IPCMessageWriter
,
createConnection
,
IConnection
,
TextDocuments
,
ITextDocument
,
Diagnostic
,
DiagnosticSeverity
,
InitializeParams
,
InitializeResult
,
TextDocumentIdentifier
,
TextDocumentPosition
,
CompletionList
,
CompletionItem
,
Hover
,
SymbolInformation
,
DocumentFormattingParams
,
IPCMessageReader
,
IPCMessageWriter
,
createConnection
,
IConnection
,
TextDocuments
,
TextDocument
,
Diagnostic
,
DiagnosticSeverity
,
InitializeParams
,
InitializeResult
,
TextDocumentPositionParams
,
CompletionList
,
CompletionItem
,
Hover
,
SymbolInformation
,
DocumentFormattingParams
,
DocumentSymbolParams
,
DocumentRangeFormattingParams
,
NotificationType
,
RequestType
}
from
'
vscode-languageserver
'
;
...
...
@@ -33,10 +32,6 @@ import {FileAssociationContribution} from './jsoncontributions/fileAssociationCo
import
*
as
nls
from
'
vscode-nls
'
;
nls
.
config
(
process
.
env
[
'
VSCODE_NLS_CONFIG
'
]);
namespace
TelemetryNotification
{
export
const
type
:
NotificationType
<
{
key
:
string
,
data
:
any
}
>
=
{
get
method
()
{
return
'
telemetry
'
;
}
};
}
namespace
SchemaAssociationNotification
{
export
const
type
:
NotificationType
<
ISchemaAssociations
>
=
{
get
method
()
{
return
'
json/schemaAssociations
'
;
}
};
}
...
...
@@ -89,7 +84,7 @@ let workspaceContext = {
let
telemetry
=
{
log
:
(
key
:
string
,
data
:
any
)
=>
{
connection
.
sendNotification
(
TelemetryNotification
.
type
,
{
key
,
data
});
connection
.
telemetry
.
logEvent
(
{
key
,
data
});
}
};
...
...
@@ -208,7 +203,7 @@ function updateConfiguration() {
}
function
validateTextDocument
(
textDocument
:
I
TextDocument
):
void
{
function
validateTextDocument
(
textDocument
:
TextDocument
):
void
{
if
(
textDocument
.
getText
().
length
===
0
)
{
// ignore empty documents
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
:
[]
});
...
...
@@ -268,28 +263,28 @@ connection.onDidChangeWatchedFiles((change) => {
}
});
function
getJSONDocument
(
document
:
I
TextDocument
):
JSONDocument
{
function
getJSONDocument
(
document
:
TextDocument
):
JSONDocument
{
return
parseJSON
(
document
.
getText
());
}
connection
.
onCompletion
((
textDocumentPosition
:
TextDocumentPosition
):
Thenable
<
CompletionList
>
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
uri
);
connection
.
onCompletion
((
textDocumentPosition
:
TextDocumentPosition
Params
):
Thenable
<
CompletionList
>
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
jsonCompletion
.
doSuggest
(
document
,
textDocumentPosition
,
jsonDocument
);
return
jsonCompletion
.
doSuggest
(
document
,
textDocumentPosition
.
position
,
jsonDocument
);
});
connection
.
onCompletionResolve
((
item
:
CompletionItem
)
:
Thenable
<
CompletionItem
>
=>
{
return
jsonCompletion
.
doResolve
(
item
);
});
connection
.
onHover
((
textDocumentPosition
:
TextDocumentPosition
):
Thenable
<
Hover
>
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
uri
);
connection
.
onHover
((
textDocumentPosition
:
TextDocumentPosition
Params
):
Thenable
<
Hover
>
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
jsonHover
.
doHover
(
document
,
textDocumentPosition
,
jsonDocument
);
return
jsonHover
.
doHover
(
document
,
textDocumentPosition
.
position
,
jsonDocument
);
});
connection
.
onDocumentSymbol
((
textDocumentIdentifier
:
TextDocumentIdentifier
):
Thenable
<
SymbolInformation
[]
>
=>
{
let
document
=
documents
.
get
(
textDocumentIdentifier
.
uri
);
connection
.
onDocumentSymbol
((
documentSymbolParams
:
DocumentSymbolParams
):
Thenable
<
SymbolInformation
[]
>
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
jsonDocumentSymbols
.
compute
(
document
,
jsonDocument
);
});
...
...
extensions/json/server/src/test/completion.test.ts
浏览文件 @
f7ed3485
...
...
@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema');
import
{
JSONCompletion
}
from
'
../jsonCompletion
'
;
import
{
XHROptions
,
XHRResponse
}
from
'
request-light
'
;
import
{
CompletionItem
,
CompletionItemKind
,
CompletionOptions
,
ITextDocument
,
TextDocumentIdentifier
,
TextDocumentPosition
,
Range
,
Position
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
{
CompletionItem
,
CompletionItemKind
,
CompletionOptions
,
TextDocument
,
TextDocumentIdentifier
,
Range
,
Position
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
{
applyEdits
}
from
'
./textEditSupport
'
;
suite
(
'
JSON Completion
'
,
()
=>
{
...
...
@@ -20,7 +20,7 @@ suite('JSON Completion', () => {
return
Promise
.
reject
<
XHRResponse
>
({
responseText
:
''
,
status
:
404
});
}
var
assertSuggestion
=
function
(
completions
:
CompletionItem
[],
label
:
string
,
documentation
?:
string
,
document
?:
I
TextDocument
,
resultText
?:
string
)
{
var
assertSuggestion
=
function
(
completions
:
CompletionItem
[],
label
:
string
,
documentation
?:
string
,
document
?:
TextDocument
,
resultText
?:
string
)
{
var
matches
=
completions
.
filter
(
function
(
completion
:
CompletionItem
)
{
return
completion
.
label
===
label
&&
(
!
documentation
||
completion
.
documentation
===
documentation
);
});
...
...
@@ -31,7 +31,7 @@ suite('JSON Completion', () => {
};
var
testSuggestionsFor
=
function
(
value
:
string
,
stringAfter
:
string
,
schema
:
JsonSchema
.
IJSONSchema
,
test
:
(
items
:
CompletionItem
[],
document
:
I
TextDocument
)
=>
void
)
:
Thenable
<
void
>
{
var
testSuggestionsFor
=
function
(
value
:
string
,
stringAfter
:
string
,
schema
:
JsonSchema
.
IJSONSchema
,
test
:
(
items
:
CompletionItem
[],
document
:
TextDocument
)
=>
void
)
:
Thenable
<
void
>
{
var
uri
=
'
test://test.json
'
;
var
idx
=
stringAfter
?
value
.
indexOf
(
stringAfter
)
:
0
;
...
...
@@ -42,10 +42,10 @@ suite('JSON Completion', () => {
schemaService
.
registerExternalSchema
(
id
,
[
"
*.json
"
],
schema
);
}
var
document
=
ITextDocument
.
create
(
uri
,
value
);
var
textDocumentLocation
=
TextDocumentPosition
.
create
(
uri
,
Position
.
create
(
0
,
idx
)
);
var
document
=
TextDocument
.
create
(
uri
,
'
json
'
,
0
,
value
);
var
position
=
Position
.
create
(
0
,
idx
);
var
jsonDoc
=
Parser
.
parse
(
value
);
return
completionProvider
.
doSuggest
(
document
,
textDocumentLoca
tion
,
jsonDoc
).
then
(
list
=>
list
.
items
).
then
(
completions
=>
{
return
completionProvider
.
doSuggest
(
document
,
posi
tion
,
jsonDoc
).
then
(
list
=>
list
.
items
).
then
(
completions
=>
{
test
(
completions
,
document
);
return
null
;
})
...
...
extensions/json/server/src/test/documentSymbols.test.ts
浏览文件 @
f7ed3485
...
...
@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema');
import
{
JSONCompletion
}
from
'
../jsonCompletion
'
;
import
{
JSONDocumentSymbols
}
from
'
../jsonDocumentSymbols
'
;
import
{
SymbolInformation
,
SymbolKind
,
TextDocumentIdentifier
,
ITextDocument
,
TextDocumentPosition
,
Range
,
Position
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
{
SymbolInformation
,
SymbolKind
,
TextDocumentIdentifier
,
TextDocument
,
Range
,
Position
,
TextEdit
}
from
'
vscode-languageserver
'
;
suite
(
'
JSON Document Symbols
'
,
()
=>
{
...
...
@@ -20,7 +20,7 @@ suite('JSON Document Symbols', () => {
var
symbolProvider
=
new
JSONDocumentSymbols
();
var
document
=
ITextDocument
.
create
(
uri
,
value
);
var
document
=
TextDocument
.
create
(
uri
,
'
json
'
,
0
,
value
);
var
jsonDoc
=
Parser
.
parse
(
value
);
return
symbolProvider
.
compute
(
document
,
jsonDoc
);
}
...
...
extensions/json/server/src/test/formatter.test.ts
浏览文件 @
f7ed3485
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
Json
=
require
(
'
jsonc-parser
'
);
import
{
I
TextDocument
,
DocumentFormattingParams
,
Range
,
Position
,
FormattingOptions
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
{
TextDocument
,
DocumentFormattingParams
,
Range
,
Position
,
FormattingOptions
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
Formatter
=
require
(
'
../jsonFormatter
'
);
import
assert
=
require
(
'
assert
'
);
import
{
applyEdits
}
from
'
./textEditSupport
'
;
...
...
@@ -20,14 +20,14 @@ suite('JSON Formatter', () => {
let
rangeEnd
=
unformatted
.
lastIndexOf
(
'
|
'
);
if
(
rangeStart
!==
-
1
&&
rangeEnd
!==
-
1
)
{
// remove '|'
var
unformattedDoc
=
ITextDocument
.
create
(
uri
,
unformatted
);
var
unformattedDoc
=
TextDocument
.
create
(
uri
,
'
json
'
,
0
,
unformatted
);
unformatted
=
unformatted
.
substring
(
0
,
rangeStart
)
+
unformatted
.
substring
(
rangeStart
+
1
,
rangeEnd
)
+
unformatted
.
substring
(
rangeEnd
+
1
);
let
startPos
=
unformattedDoc
.
positionAt
(
rangeStart
);
let
endPos
=
unformattedDoc
.
positionAt
(
rangeEnd
);
range
=
Range
.
create
(
startPos
,
endPos
);
}
var
document
=
ITextDocument
.
create
(
uri
,
unformatted
);
var
document
=
TextDocument
.
create
(
uri
,
'
json
'
,
0
,
unformatted
);
let
edits
=
Formatter
.
format
(
document
,
range
,
{
tabSize
:
2
,
insertSpaces
:
insertSpaces
});
let
formatted
=
applyEdits
(
document
,
edits
);
assert
.
equal
(
formatted
,
expected
);
...
...
@@ -308,7 +308,7 @@ suite('JSON Formatter', () => {
format
(
content
,
expected
);
});
test
(
'
multiple mixed comments on same line
'
,
()
=>
{
var
content
=
[
'
[ /*comment*/ /*comment*/ // comment
'
,
...
...
extensions/json/server/src/test/hover.test.ts
浏览文件 @
f7ed3485
...
...
@@ -12,7 +12,7 @@ import {JSONCompletion} from '../jsonCompletion';
import
{
XHROptions
,
XHRResponse
}
from
'
request-light
'
;
import
{
JSONHover
}
from
'
../jsonHover
'
;
import
{
Hover
,
ITextDocument
,
TextDocumentIdentifier
,
TextDocumentPosition
,
Range
,
Position
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
{
Hover
,
TextDocument
,
TextDocumentIdentifier
,
TextDocumentPositionParams
,
Range
,
Position
,
TextEdit
}
from
'
vscode-languageserver
'
;
suite
(
'
JSON Hover
'
,
()
=>
{
...
...
@@ -24,10 +24,9 @@ suite('JSON Hover', () => {
var
id
=
"
http://myschemastore/test1
"
;
schemaService
.
registerExternalSchema
(
id
,
[
"
*.json
"
],
schema
);
var
document
=
ITextDocument
.
create
(
uri
,
value
);
var
textDocumentLocation
=
TextDocumentPosition
.
create
(
uri
,
position
);
var
document
=
TextDocument
.
create
(
uri
,
'
json
'
,
0
,
value
);
var
jsonDoc
=
Parser
.
parse
(
value
);
return
hoverProvider
.
doHover
(
document
,
textDocumentLoca
tion
,
jsonDoc
);
return
hoverProvider
.
doHover
(
document
,
posi
tion
,
jsonDoc
);
}
var
requestService
=
function
(
options
:
XHROptions
):
Promise
<
XHRResponse
>
{
...
...
extensions/json/server/src/test/textEditSupport.ts
浏览文件 @
f7ed3485
...
...
@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
I
TextDocument
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
{
TextDocument
,
TextEdit
}
from
'
vscode-languageserver
'
;
import
assert
=
require
(
'
assert
'
);
export
function
applyEdits
(
document
:
I
TextDocument
,
edits
:
TextEdit
[])
:
string
{
export
function
applyEdits
(
document
:
TextDocument
,
edits
:
TextEdit
[])
:
string
{
let
formatted
=
document
.
getText
();
let
sortedEdits
=
edits
.
sort
((
a
,
b
)
=>
document
.
offsetAt
(
b
.
range
.
start
)
-
document
.
offsetAt
(
a
.
range
.
start
));
let
lastOffset
=
formatted
.
length
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录