Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
baed6fa9
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,发现更多精彩内容 >>
提交
baed6fa9
编写于
9月 15, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[html] multi folder settings optimizations
上级
bde20085
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
116 addition
and
41 deletion
+116
-41
extensions/json/client/src/jsonMain.ts
extensions/json/client/src/jsonMain.ts
+52
-26
extensions/json/client/src/utils/hash.ts
extensions/json/client/src/utils/hash.ts
+59
-0
extensions/json/server/npm-shrinkwrap.json
extensions/json/server/npm-shrinkwrap.json
+2
-2
extensions/json/server/package.json
extensions/json/server/package.json
+1
-1
extensions/json/server/src/jsonServerMain.ts
extensions/json/server/src/jsonServerMain.ts
+2
-12
未找到文件。
extensions/json/client/src/jsonMain.ts
浏览文件 @
baed6fa9
...
@@ -10,11 +10,11 @@ import { workspace, languages, ExtensionContext, extensions, Uri, TextDocument,
...
@@ -10,11 +10,11 @@ import { workspace, languages, ExtensionContext, extensions, Uri, TextDocument,
import
{
LanguageClient
,
LanguageClientOptions
,
RequestType
,
ServerOptions
,
TransportKind
,
NotificationType
,
DidChangeConfigurationNotification
}
from
'
vscode-languageclient
'
;
import
{
LanguageClient
,
LanguageClientOptions
,
RequestType
,
ServerOptions
,
TransportKind
,
NotificationType
,
DidChangeConfigurationNotification
}
from
'
vscode-languageclient
'
;
import
TelemetryReporter
from
'
vscode-extension-telemetry
'
;
import
TelemetryReporter
from
'
vscode-extension-telemetry
'
;
import
{
ConfigurationFeature
}
from
'
vscode-languageclient/lib/proposed
'
;
import
{
ConfigurationFeature
}
from
'
vscode-languageclient/lib/proposed
'
;
import
{
DocumentColorRequest
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
{
DocumentColorRequest
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
*
as
nls
from
'
vscode-nls
'
;
import
*
as
nls
from
'
vscode-nls
'
;
import
{
hash
}
from
'
./utils/hash
'
;
let
localize
=
nls
.
loadMessageBundle
();
let
localize
=
nls
.
loadMessageBundle
();
namespace
VSCodeContentRequest
{
namespace
VSCodeContentRequest
{
...
@@ -192,8 +192,6 @@ function getSettings(): Settings {
...
@@ -192,8 +192,6 @@ function getSettings(): Settings {
let
httpSettings
=
workspace
.
getConfiguration
(
'
http
'
);
let
httpSettings
=
workspace
.
getConfiguration
(
'
http
'
);
let
jsonSettings
=
workspace
.
getConfiguration
(
'
json
'
);
let
jsonSettings
=
workspace
.
getConfiguration
(
'
json
'
);
let
schemas
=
[];
let
settings
:
Settings
=
{
let
settings
:
Settings
=
{
http
:
{
http
:
{
proxy
:
httpSettings
.
get
(
'
proxy
'
),
proxy
:
httpSettings
.
get
(
'
proxy
'
),
...
@@ -201,41 +199,69 @@ function getSettings(): Settings {
...
@@ -201,41 +199,69 @@ function getSettings(): Settings {
},
},
json
:
{
json
:
{
format
:
jsonSettings
.
get
(
'
format
'
),
format
:
jsonSettings
.
get
(
'
format
'
),
schemas
:
schemas
,
schemas
:
[],
}
};
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
);
if
(
!
url
)
{
continue
;
}
let
schemaSetting
=
schemaSettingsById
[
url
];
if
(
!
schemaSetting
)
{
schemaSetting
=
schemaSettingsById
[
url
]
=
{
url
,
fileMatch
:
[]
};
settings
.
json
.
schemas
.
push
(
schemaSetting
);
}
let
fileMatches
=
setting
.
fileMatch
;
if
(
Array
.
isArray
(
fileMatches
))
{
if
(
fileMatchPrefix
)
{
fileMatches
=
fileMatches
.
map
(
m
=>
fileMatchPrefix
+
m
);
}
schemaSetting
.
fileMatch
.
push
(...
fileMatches
);
}
if
(
setting
.
schema
)
{
schemaSetting
.
schema
=
setting
.
schema
;
}
}
}
};
};
let
settingsSchemas
=
jsonSettings
.
get
(
'
schemas
'
);
if
(
Array
.
isArray
(
settingsSchemas
))
{
schemas
.
push
(...
settingsSchemas
);
}
// merge global and folder settings. Qualify all file matches with the folder path.
let
globalSettings
=
jsonSettings
.
get
<
JSONSchemaSettings
[]
>
(
'
schemas
'
);
if
(
Array
.
isArray
(
globalSettings
))
{
collectSchemaSettings
(
globalSettings
,
workspace
.
rootPath
);
}
let
folders
=
workspace
.
workspaceFolders
;
let
folders
=
workspace
.
workspaceFolders
;
if
(
folders
)
{
if
(
folders
)
{
fo
lders
.
forEach
(
folder
=>
{
fo
r
(
let
folder
of
folders
)
{
let
jsonConfig
=
workspace
.
getConfiguration
(
'
json
'
,
folder
.
uri
)
;
let
folderUri
=
folder
.
uri
;
let
schemaConfigInfo
=
jsonConfig
.
inspect
<
JSONSchemaSettings
[]
>
(
'
schemas
'
);
let
schemaConfigInfo
=
workspace
.
getConfiguration
(
'
json
'
,
folderUri
)
.
inspect
<
JSONSchemaSettings
[]
>
(
'
schemas
'
);
let
folderSchemas
=
schemaConfigInfo
.
workspaceFolderValue
;
let
folderSchemas
=
schemaConfigInfo
.
workspaceFolderValue
;
if
(
Array
.
isArray
(
folderSchemas
))
{
if
(
Array
.
isArray
(
folderSchemas
))
{
folderSchemas
.
forEach
(
schema
=>
{
let
folderPath
=
folderUri
.
toString
();
let
url
=
schema
.
url
;
if
(
folderPath
[
folderPath
.
length
-
1
]
!==
'
/
'
)
{
if
(
!
url
&&
schema
.
schema
)
{
folderPath
=
folderPath
+
'
/
'
;
url
=
schema
.
schema
.
id
;
}
}
collectSchemaSettings
(
folderSchemas
,
folderUri
.
fsPath
,
folderPath
+
'
*
'
);
if
(
url
&&
url
[
0
]
===
'
.
'
)
{
url
=
Uri
.
file
(
path
.
normalize
(
path
.
join
(
folder
.
uri
.
fsPath
,
url
))).
toString
();
}
let
fileMatch
=
schema
.
fileMatch
;
if
(
fileMatch
)
{
fileMatch
=
fileMatch
.
map
(
m
=>
folder
.
uri
.
toString
()
+
'
*
'
+
m
);
}
schemas
.
push
({
url
,
fileMatch
,
schema
:
schema
.
schema
});
});
};
};
}
)
;
};
}
}
return
settings
;
return
settings
;
}
}
function
getSchemaId
(
schema
:
JSONSchemaSettings
,
rootPath
?:
string
)
{
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
();
}
return
url
;
}
function
getPackageInfo
(
context
:
ExtensionContext
):
IPackageInfo
{
function
getPackageInfo
(
context
:
ExtensionContext
):
IPackageInfo
{
let
extensionPackage
=
require
(
context
.
asAbsolutePath
(
'
./package.json
'
));
let
extensionPackage
=
require
(
context
.
asAbsolutePath
(
'
./package.json
'
));
if
(
extensionPackage
)
{
if
(
extensionPackage
)
{
...
...
extensions/json/client/src/utils/hash.ts
0 → 100644
浏览文件 @
baed6fa9
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
/**
* Return a hash value for an object.
*/
export
function
hash
(
obj
:
any
,
hashVal
=
0
):
number
{
switch
(
typeof
obj
)
{
case
'
object
'
:
if
(
obj
===
null
)
{
return
numberHash
(
349
,
hashVal
);
}
else
if
(
Array
.
isArray
(
obj
))
{
return
arrayHash
(
obj
,
hashVal
);
}
return
objectHash
(
obj
,
hashVal
);
case
'
string
'
:
return
stringHash
(
obj
,
hashVal
);
case
'
boolean
'
:
return
booleanHash
(
obj
,
hashVal
);
case
'
number
'
:
return
numberHash
(
obj
,
hashVal
);
case
'
undefined
'
:
return
numberHash
(
obj
,
937
);
default
:
return
numberHash
(
obj
,
617
);
}
}
function
numberHash
(
val
:
number
,
initialHashVal
:
number
):
number
{
return
(((
initialHashVal
<<
5
)
-
initialHashVal
)
+
val
)
|
0
;
// hashVal * 31 + ch, keep as int32
}
function
booleanHash
(
b
:
boolean
,
initialHashVal
:
number
):
number
{
return
numberHash
(
b
?
433
:
863
,
initialHashVal
);
}
function
stringHash
(
s
:
string
,
hashVal
:
number
)
{
hashVal
=
numberHash
(
149417
,
hashVal
);
for
(
let
i
=
0
,
length
=
s
.
length
;
i
<
length
;
i
++
)
{
hashVal
=
numberHash
(
s
.
charCodeAt
(
i
),
hashVal
);
}
return
hashVal
;
}
function
arrayHash
(
arr
:
any
[],
initialHashVal
:
number
):
number
{
initialHashVal
=
numberHash
(
104579
,
initialHashVal
);
return
arr
.
reduce
((
hashVal
,
item
)
=>
hash
(
item
,
hashVal
),
initialHashVal
);
}
function
objectHash
(
obj
:
any
,
initialHashVal
:
number
):
number
{
initialHashVal
=
numberHash
(
181387
,
initialHashVal
);
return
Object
.
keys
(
obj
).
sort
().
reduce
((
hashVal
,
key
)
=>
{
hashVal
=
stringHash
(
key
,
hashVal
);
return
hash
(
obj
[
key
],
hashVal
);
},
initialHashVal
);
}
extensions/json/server/npm-shrinkwrap.json
浏览文件 @
baed6fa9
...
@@ -43,9 +43,9 @@
...
@@ -43,9 +43,9 @@
"resolved"
:
"https://registry.npmjs.org/request-light/-/request-light-0.2.1.tgz"
"resolved"
:
"https://registry.npmjs.org/request-light/-/request-light-0.2.1.tgz"
},
},
"vscode-json-languageservice"
:
{
"vscode-json-languageservice"
:
{
"version"
:
"2.0.1
6
"
,
"version"
:
"2.0.1
8
"
,
"from"
:
"vscode-json-languageservice@next"
,
"from"
:
"vscode-json-languageservice@next"
,
"resolved"
:
"https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-2.0.1
6
.tgz"
"resolved"
:
"https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-2.0.1
8
.tgz"
},
},
"vscode-jsonrpc"
:
{
"vscode-jsonrpc"
:
{
"version"
:
"3.3.1"
,
"version"
:
"3.3.1"
,
...
...
extensions/json/server/package.json
浏览文件 @
baed6fa9
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
"dependencies"
:
{
"dependencies"
:
{
"jsonc-parser"
:
"^1.0.0"
,
"jsonc-parser"
:
"^1.0.0"
,
"request-light"
:
"^0.2.1"
,
"request-light"
:
"^0.2.1"
,
"vscode-json-languageservice"
:
"^2.0.1
6
"
,
"vscode-json-languageservice"
:
"^2.0.1
8
"
,
"vscode-languageserver"
:
"3.4.0-next.6"
,
"vscode-languageserver"
:
"3.4.0-next.6"
,
"vscode-languageserver-protocol"
:
"^3.1.1"
,
"vscode-languageserver-protocol"
:
"^3.1.1"
,
"vscode-nls"
:
"^2.0.2"
,
"vscode-nls"
:
"^2.0.2"
,
...
...
extensions/json/server/src/jsonServerMain.ts
浏览文件 @
baed6fa9
...
@@ -13,7 +13,6 @@ import {
...
@@ -13,7 +13,6 @@ import {
import
{
DocumentColorRequest
,
ServerCapabilities
as
CPServerCapabilities
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
{
DocumentColorRequest
,
ServerCapabilities
as
CPServerCapabilities
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
{
xhr
,
XHRResponse
,
configure
as
configureHttpRequests
,
getErrorStatusDescription
}
from
'
request-light
'
;
import
{
xhr
,
XHRResponse
,
configure
as
configureHttpRequests
,
getErrorStatusDescription
}
from
'
request-light
'
;
import
path
=
require
(
'
path
'
);
import
fs
=
require
(
'
fs
'
);
import
fs
=
require
(
'
fs
'
);
import
URI
from
'
vscode-uri
'
;
import
URI
from
'
vscode-uri
'
;
import
*
as
URL
from
'
url
'
;
import
*
as
URL
from
'
url
'
;
...
@@ -54,9 +53,7 @@ let clientDynamicRegisterSupport = false;
...
@@ -54,9 +53,7 @@ let clientDynamicRegisterSupport = false;
// After the server has started the client sends an initilize request. The server receives
// After the server has started the client sends an initilize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilities.
// in the passed params the rootPath of the workspace plus the client capabilities.
let
workspaceRoot
:
URI
;
connection
.
onInitialize
((
params
:
InitializeParams
):
InitializeResult
=>
{
connection
.
onInitialize
((
params
:
InitializeParams
):
InitializeResult
=>
{
workspaceRoot
=
URI
.
parse
(
params
.
rootPath
);
function
hasClientCapability
(...
keys
:
string
[])
{
function
hasClientCapability
(...
keys
:
string
[])
{
let
c
=
params
.
capabilities
;
let
c
=
params
.
capabilities
;
...
@@ -192,19 +189,12 @@ function updateConfiguration() {
...
@@ -192,19 +189,12 @@ function updateConfiguration() {
}
}
}
}
if
(
jsonConfigurationSettings
)
{
if
(
jsonConfigurationSettings
)
{
jsonConfigurationSettings
.
forEach
(
schema
=>
{
jsonConfigurationSettings
.
forEach
(
(
schema
,
index
)
=>
{
let
uri
=
schema
.
url
;
let
uri
=
schema
.
url
;
if
(
!
uri
&&
schema
.
schema
)
{
if
(
!
uri
&&
schema
.
schema
)
{
uri
=
schema
.
schema
.
id
;
uri
=
schema
.
schema
.
id
||
`vscode://schemas/custom/
${
index
}
`
;
}
if
(
!
uri
&&
schema
.
fileMatch
)
{
uri
=
'
vscode://schemas/custom/
'
+
encodeURIComponent
(
schema
.
fileMatch
.
join
(
'
&
'
));
}
}
if
(
uri
)
{
if
(
uri
)
{
if
(
uri
[
0
]
===
'
.
'
&&
workspaceRoot
)
{
// workspace relative path
uri
=
URI
.
file
(
path
.
normalize
(
path
.
join
(
workspaceRoot
.
fsPath
,
uri
))).
toString
();
}
languageSettings
.
schemas
.
push
({
uri
,
fileMatch
:
schema
.
fileMatch
,
schema
:
schema
.
schema
});
languageSettings
.
schemas
.
push
({
uri
,
fileMatch
:
schema
.
fileMatch
,
schema
:
schema
.
schema
});
}
}
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录