Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
27aaa79d
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,发现更多精彩内容 >>
提交
27aaa79d
编写于
2月 18, 2020
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't use rootPath in built-in extension. For #90562
上级
595f9845
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
73 addition
and
56 deletion
+73
-56
extensions/json-language-features/client/src/jsonMain.ts
extensions/json-language-features/client/src/jsonMain.ts
+73
-56
未找到文件。
extensions/json-language-features/client/src/jsonMain.ts
浏览文件 @
27aaa79d
...
...
@@ -76,29 +76,29 @@ let telemetryReporter: TelemetryReporter | undefined;
export
function
activate
(
context
:
ExtensionContext
)
{
le
t
toDispose
=
context
.
subscriptions
;
cons
t
toDispose
=
context
.
subscriptions
;
let
rangeFormatting
:
Disposable
|
undefined
=
undefined
;
le
t
packageInfo
=
getPackageInfo
(
context
);
cons
t
packageInfo
=
getPackageInfo
(
context
);
telemetryReporter
=
packageInfo
&&
new
TelemetryReporter
(
packageInfo
.
name
,
packageInfo
.
version
,
packageInfo
.
aiKey
);
le
t
serverMain
=
readJSONFile
(
context
.
asAbsolutePath
(
'
./server/package.json
'
)).
main
;
le
t
serverModule
=
context
.
asAbsolutePath
(
path
.
join
(
'
server
'
,
serverMain
));
cons
t
serverMain
=
readJSONFile
(
context
.
asAbsolutePath
(
'
./server/package.json
'
)).
main
;
cons
t
serverModule
=
context
.
asAbsolutePath
(
path
.
join
(
'
server
'
,
serverMain
));
// The debug options for the server
le
t
debugOptions
=
{
execArgv
:
[
'
--nolazy
'
,
'
--inspect=
'
+
(
9000
+
Math
.
round
(
Math
.
random
()
*
10000
))]
};
cons
t
debugOptions
=
{
execArgv
:
[
'
--nolazy
'
,
'
--inspect=
'
+
(
9000
+
Math
.
round
(
Math
.
random
()
*
10000
))]
};
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
le
t
serverOptions
:
ServerOptions
=
{
cons
t
serverOptions
:
ServerOptions
=
{
run
:
{
module
:
serverModule
,
transport
:
TransportKind
.
ipc
},
debug
:
{
module
:
serverModule
,
transport
:
TransportKind
.
ipc
,
options
:
debugOptions
}
};
le
t
documentSelector
=
[
'
json
'
,
'
jsonc
'
];
cons
t
documentSelector
=
[
'
json
'
,
'
jsonc
'
];
le
t
schemaResolutionErrorStatusBarItem
=
window
.
createStatusBarItem
({
cons
t
schemaResolutionErrorStatusBarItem
=
window
.
createStatusBarItem
({
id
:
'
status.json.resolveError
'
,
name
:
localize
(
'
json.resolveError
'
,
"
JSON: Schema Resolution Error
"
),
alignment
:
StatusBarAlignment
.
Right
,
...
...
@@ -109,10 +109,10 @@ export function activate(context: ExtensionContext) {
schemaResolutionErrorStatusBarItem
.
text
=
'
$(alert)
'
;
toDispose
.
push
(
schemaResolutionErrorStatusBarItem
);
le
t
fileSchemaErrors
=
new
Map
<
string
,
string
>
();
cons
t
fileSchemaErrors
=
new
Map
<
string
,
string
>
();
// Options to control the language client
le
t
clientOptions
:
LanguageClientOptions
=
{
cons
t
clientOptions
:
LanguageClientOptions
=
{
// Register the server for json documents
documentSelector
,
initializationOptions
:
{
...
...
@@ -172,17 +172,17 @@ export function activate(context: ExtensionContext) {
};
// Create the language client and start the client.
le
t
client
=
new
LanguageClient
(
'
json
'
,
localize
(
'
jsonserver.name
'
,
'
JSON Language Server
'
),
serverOptions
,
clientOptions
);
cons
t
client
=
new
LanguageClient
(
'
json
'
,
localize
(
'
jsonserver.name
'
,
'
JSON Language Server
'
),
serverOptions
,
clientOptions
);
client
.
registerProposedFeatures
();
le
t
disposable
=
client
.
start
();
cons
t
disposable
=
client
.
start
();
toDispose
.
push
(
disposable
);
client
.
onReady
().
then
(()
=>
{
const
schemaDocuments
:
{
[
uri
:
string
]:
boolean
}
=
{};
// handle content request
client
.
onRequest
(
VSCodeContentRequest
.
type
,
(
uriPath
:
string
)
=>
{
le
t
uri
=
Uri
.
parse
(
uriPath
);
cons
t
uri
=
Uri
.
parse
(
uriPath
);
if
(
uri
.
scheme
!==
'
http
'
&&
uri
.
scheme
!==
'
https
'
)
{
return
workspace
.
openTextDocument
(
uri
).
then
(
doc
=>
{
schemaDocuments
[
uri
.
toString
()]
=
true
;
...
...
@@ -212,7 +212,7 @@ export function activate(context: ExtensionContext) {
}
});
le
t
handleContentChange
=
(
uriString
:
string
)
=>
{
cons
t
handleContentChange
=
(
uriString
:
string
)
=>
{
if
(
schemaDocuments
[
uriString
])
{
client
.
sendNotification
(
SchemaContentChangeNotification
.
type
,
uriString
);
return
true
;
...
...
@@ -220,7 +220,7 @@ export function activate(context: ExtensionContext) {
return
false
;
};
le
t
handleActiveEditorChange
=
(
activeEditor
?:
TextEditor
)
=>
{
cons
t
handleActiveEditorChange
=
(
activeEditor
?:
TextEditor
)
=>
{
if
(
!
activeEditor
)
{
return
;
}
...
...
@@ -244,7 +244,7 @@ export function activate(context: ExtensionContext) {
}));
toDispose
.
push
(
window
.
onDidChangeActiveTextEditor
(
handleActiveEditorChange
));
le
t
handleRetryResolveSchemaCommand
=
()
=>
{
cons
t
handleRetryResolveSchemaCommand
=
()
=>
{
if
(
window
.
activeTextEditor
)
{
schemaResolutionErrorStatusBarItem
.
text
=
'
$(watch)
'
;
const
activeDocUri
=
window
.
activeTextEditor
.
document
.
uri
.
toString
();
...
...
@@ -282,7 +282,7 @@ export function activate(context: ExtensionContext) {
});
le
t
languageConfiguration
:
LanguageConfiguration
=
{
cons
t
languageConfiguration
:
LanguageConfiguration
=
{
wordPattern
:
/
(
"
(?:[^\\\"]
*
(?:\\
.
)?)
*"
?)
|
[^\s
{}
\[\]
,:
]
+/
,
indentationRules
:
{
increaseIndentPattern
:
/
(
{+
(?=([^
"
]
*"
[^
"
]
*"
)
*
[^
"}
]
*$
))
|
(\[
+
(?=([^
"
]
*"
[^
"
]
*"
)
*
[^
"
\]]
*$
))
/
,
...
...
@@ -300,7 +300,7 @@ export function activate(context: ExtensionContext) {
}
else
if
(
formatEnabled
&&
!
rangeFormatting
)
{
rangeFormatting
=
languages
.
registerDocumentRangeFormattingEditProvider
(
documentSelector
,
{
provideDocumentRangeFormattingEdits
(
document
:
TextDocument
,
range
:
Range
,
options
:
FormattingOptions
,
token
:
CancellationToken
):
ProviderResult
<
TextEdit
[]
>
{
le
t
params
:
DocumentRangeFormattingParams
=
{
cons
t
params
:
DocumentRangeFormattingParams
=
{
textDocument
:
client
.
code2ProtocolConverter
.
asTextDocumentIdentifier
(
document
),
range
:
client
.
code2ProtocolConverter
.
asRange
(
range
),
options
:
client
.
code2ProtocolConverter
.
asFormattingOptions
(
options
)
...
...
@@ -325,11 +325,11 @@ export function deactivate(): Promise<any> {
}
function
getSchemaAssociation
(
_context
:
ExtensionContext
):
ISchemaAssociations
{
le
t
associations
:
ISchemaAssociations
=
{};
cons
t
associations
:
ISchemaAssociations
=
{};
extensions
.
all
.
forEach
(
extension
=>
{
le
t
packageJSON
=
extension
.
packageJSON
;
cons
t
packageJSON
=
extension
.
packageJSON
;
if
(
packageJSON
&&
packageJSON
.
contributes
&&
packageJSON
.
contributes
.
jsonValidation
)
{
le
t
jsonValidation
=
packageJSON
.
contributes
.
jsonValidation
;
cons
t
jsonValidation
=
packageJSON
.
contributes
.
jsonValidation
;
if
(
Array
.
isArray
(
jsonValidation
))
{
jsonValidation
.
forEach
(
jv
=>
{
let
{
fileMatch
,
url
}
=
jv
;
...
...
@@ -359,11 +359,11 @@ function getSchemaAssociation(_context: ExtensionContext): ISchemaAssociations {
}
function
getSettings
():
Settings
{
le
t
httpSettings
=
workspace
.
getConfiguration
(
'
http
'
);
cons
t
httpSettings
=
workspace
.
getConfiguration
(
'
http
'
);
le
t
resultLimit
:
number
=
Math
.
trunc
(
Math
.
max
(
0
,
Number
(
workspace
.
getConfiguration
().
get
(
'
json.maxItemsComputed
'
))))
||
5000
;
cons
t
resultLimit
:
number
=
Math
.
trunc
(
Math
.
max
(
0
,
Number
(
workspace
.
getConfiguration
().
get
(
'
json.maxItemsComputed
'
))))
||
5000
;
le
t
settings
:
Settings
=
{
cons
t
settings
:
Settings
=
{
http
:
{
proxy
:
httpSettings
.
get
(
'
proxy
'
),
proxyStrictSSL
:
httpSettings
.
get
(
'
proxyStrictSSL
'
)
...
...
@@ -373,10 +373,18 @@ function getSettings(): Settings {
resultLimit
}
};
let
schemaSettingsById
:
{
[
schemaId
:
string
]:
JSONSchemaSettings
}
=
Object
.
create
(
null
);
let
collectSchemaSettings
=
(
schemaSettings
:
JSONSchemaSettings
[],
rootPath
?:
string
,
fileMatchPrefix
?:
string
)
=>
{
for
(
let
setting
of
schemaSettings
)
{
let
url
=
getSchemaId
(
setting
,
rootPath
);
const
schemaSettingsById
:
{
[
schemaId
:
string
]:
JSONSchemaSettings
}
=
Object
.
create
(
null
);
const
collectSchemaSettings
=
(
schemaSettings
:
JSONSchemaSettings
[],
folderUri
?:
Uri
,
isMultiRoot
?:
boolean
)
=>
{
let
fileMatchPrefix
=
undefined
;
if
(
folderUri
&&
isMultiRoot
)
{
fileMatchPrefix
=
folderUri
.
toString
();
if
(
fileMatchPrefix
[
fileMatchPrefix
.
length
-
1
]
===
'
/
'
)
{
fileMatchPrefix
=
fileMatchPrefix
.
substr
(
0
,
fileMatchPrefix
.
length
-
1
);
}
}
for
(
const
setting
of
schemaSettings
)
{
const
url
=
getSchemaId
(
setting
,
folderUri
);
if
(
!
url
)
{
continue
;
}
...
...
@@ -385,69 +393,78 @@ function getSettings(): Settings {
schemaSetting
=
schemaSettingsById
[
url
]
=
{
url
,
fileMatch
:
[]
};
settings
.
json
!
.
schemas
!
.
push
(
schemaSetting
);
}
let
fileMatches
=
setting
.
fileMatch
;
let
resultingFileMatches
=
schemaSetting
.
fileMatch
!
;
const
fileMatches
=
setting
.
fileMatch
;
if
(
Array
.
isArray
(
fileMatches
))
{
if
(
fileMatchPrefix
)
{
for
(
let
fileMatch
of
fileMatches
)
{
const
resultingFileMatches
=
schemaSetting
.
fileMatch
||
[];
schemaSetting
.
fileMatch
=
resultingFileMatches
;
const
addMatch
=
(
pattern
:
string
)
=>
{
// filter duplicates
if
(
resultingFileMatches
.
indexOf
(
pattern
)
===
-
1
)
{
resultingFileMatches
.
push
(
pattern
);
}
};
for
(
const
fileMatch
of
fileMatches
)
{
if
(
fileMatchPrefix
)
{
if
(
fileMatch
[
0
]
===
'
/
'
)
{
resultingFileMatches
.
pus
h
(
fileMatchPrefix
+
fileMatch
);
resultingFileMatches
.
pus
h
(
fileMatchPrefix
+
'
/*
'
+
fileMatch
);
addMatc
h
(
fileMatchPrefix
+
fileMatch
);
addMatc
h
(
fileMatchPrefix
+
'
/*
'
+
fileMatch
);
}
else
{
resultingFileMatches
.
pus
h
(
fileMatchPrefix
+
'
/
'
+
fileMatch
);
resultingFileMatches
.
pus
h
(
fileMatchPrefix
+
'
/*/
'
+
fileMatch
);
addMatc
h
(
fileMatchPrefix
+
'
/
'
+
fileMatch
);
addMatc
h
(
fileMatchPrefix
+
'
/*/
'
+
fileMatch
);
}
}
else
{
addMatch
(
fileMatch
);
}
}
else
{
resultingFileMatches
.
push
(...
fileMatches
);
}
}
if
(
setting
.
schema
)
{
if
(
setting
.
schema
&&
!
schemaSetting
.
schema
)
{
schemaSetting
.
schema
=
setting
.
schema
;
}
}
};
const
folders
=
workspace
.
workspaceFolders
;
// merge global and folder settings. Qualify all file matches with the folder path.
le
t
globalSettings
=
workspace
.
getConfiguration
(
'
json
'
,
null
).
get
<
JSONSchemaSettings
[]
>
(
'
schemas
'
);
cons
t
globalSettings
=
workspace
.
getConfiguration
(
'
json
'
,
null
).
get
<
JSONSchemaSettings
[]
>
(
'
schemas
'
);
if
(
Array
.
isArray
(
globalSettings
))
{
collectSchemaSettings
(
globalSettings
,
workspace
.
rootPath
);
if
(
!
folders
)
{
collectSchemaSettings
(
globalSettings
);
}
}
let
folders
=
workspace
.
workspaceFolders
;
if
(
folders
)
{
for
(
let
folder
of
folders
)
{
let
folderUri
=
folder
.
uri
;
const
isMultiRoot
=
folders
.
length
>
1
;
for
(
const
folder
of
folders
)
{
const
folderUri
=
folder
.
uri
;
le
t
schemaConfigInfo
=
workspace
.
getConfiguration
(
'
json
'
,
folderUri
).
inspect
<
JSONSchemaSettings
[]
>
(
'
schemas
'
);
cons
t
schemaConfigInfo
=
workspace
.
getConfiguration
(
'
json
'
,
folderUri
).
inspect
<
JSONSchemaSettings
[]
>
(
'
schemas
'
);
le
t
folderSchemas
=
schemaConfigInfo
!
.
workspaceFolderValue
;
cons
t
folderSchemas
=
schemaConfigInfo
!
.
workspaceFolderValue
;
if
(
Array
.
isArray
(
folderSchemas
))
{
let
folderPath
=
folderUri
.
toString
();
if
(
folderPath
[
folderPath
.
length
-
1
]
===
'
/
'
)
{
folderPath
=
folderPath
.
substr
(
0
,
folderPath
.
length
-
1
);
}
collectSchemaSettings
(
folderSchemas
,
folderUri
.
fsPath
,
folderPath
);
collectSchemaSettings
(
folderSchemas
,
folderUri
,
isMultiRoot
);
}
if
(
Array
.
isArray
(
globalSettings
))
{
collectSchemaSettings
(
globalSettings
,
folderUri
,
isMultiRoot
);
}
}
}
return
settings
;
}
function
getSchemaId
(
schema
:
JSONSchemaSettings
,
rootPath
?:
string
)
{
function
getSchemaId
(
schema
:
JSONSchemaSettings
,
folderUri
?:
Uri
)
{
let
url
=
schema
.
url
;
if
(
!
url
)
{
if
(
schema
.
schema
)
{
url
=
schema
.
schema
.
id
||
`vscode://schemas/custom/
${
encodeURIComponent
(
hash
(
schema
.
schema
).
toString
(
16
))}
`
;
}
}
else
if
(
rootPath
&&
(
url
[
0
]
===
'
.
'
||
url
[
0
]
===
'
/
'
))
{
url
=
Uri
.
file
(
path
.
normalize
(
path
.
join
(
rootPath
,
url
))
).
toString
();
}
else
if
(
folderUri
&&
(
url
[
0
]
===
'
.
'
||
url
[
0
]
===
'
/
'
))
{
url
=
folderUri
.
with
({
path
:
path
.
posix
.
join
(
folderUri
.
path
,
url
)
}
).
toString
();
}
return
url
;
}
function
getPackageInfo
(
context
:
ExtensionContext
):
IPackageInfo
|
undefined
{
le
t
extensionPackage
=
readJSONFile
(
context
.
asAbsolutePath
(
'
./package.json
'
));
cons
t
extensionPackage
=
readJSONFile
(
context
.
asAbsolutePath
(
'
./package.json
'
));
if
(
extensionPackage
)
{
return
{
name
:
extensionPackage
.
name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录