Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
0e3d8542
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,发现更多精彩内容 >>
提交
0e3d8542
编写于
9月 21, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[json] provide colorpresentations in language server
上级
8641e840
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
60 addition
and
52 deletion
+60
-52
extensions/json/client/src/jsonMain.ts
extensions/json/client/src/jsonMain.ts
+19
-21
extensions/json/npm-shrinkwrap.json
extensions/json/npm-shrinkwrap.json
+12
-12
extensions/json/package.json
extensions/json/package.json
+2
-2
extensions/json/server/npm-shrinkwrap.json
extensions/json/server/npm-shrinkwrap.json
+13
-13
extensions/json/server/package.json
extensions/json/server/package.json
+4
-3
extensions/json/server/src/jsonServerMain.ts
extensions/json/server/src/jsonServerMain.ts
+10
-1
未找到文件。
extensions/json/client/src/jsonMain.ts
浏览文件 @
0e3d8542
...
...
@@ -6,11 +6,11 @@
import
*
as
path
from
'
path
'
;
import
{
workspace
,
languages
,
ExtensionContext
,
extensions
,
Uri
,
TextDocument
,
ColorInformation
,
Color
,
ColorPresentation
,
TextEdit
}
from
'
vscode
'
;
import
{
workspace
,
languages
,
ExtensionContext
,
extensions
,
Uri
,
TextDocument
,
ColorInformation
,
Color
,
ColorPresentation
}
from
'
vscode
'
;
import
{
LanguageClient
,
LanguageClientOptions
,
RequestType
,
ServerOptions
,
TransportKind
,
NotificationType
,
DidChangeConfigurationNotification
}
from
'
vscode-languageclient
'
;
import
TelemetryReporter
from
'
vscode-extension-telemetry
'
;
import
{
ConfigurationFeature
}
from
'
vscode-languageclient/lib/proposed
'
;
import
{
DocumentColorRequest
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
{
ConfigurationFeature
}
from
'
vscode-languageclient/lib/
configuration.
proposed
'
;
import
{
DocumentColorRequest
,
DocumentColorParams
,
ColorPresentationParams
,
ColorPresentationRequest
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
*
as
nls
from
'
vscode-nls
'
;
...
...
@@ -116,14 +116,12 @@ export function activate(context: ExtensionContext) {
client
.
sendNotification
(
SchemaAssociationNotification
.
type
,
getSchemaAssociation
(
context
));
var
_toTwoDigitHex
=
function
(
n
:
number
):
string
{
const
r
=
n
.
toString
(
16
);
return
r
.
length
!==
2
?
'
0
'
+
r
:
r
;
};
// register color provider
context
.
subscriptions
.
push
(
languages
.
registerColorProvider
(
documentSelector
,
{
provideDocumentColors
(
document
:
TextDocument
):
Thenable
<
ColorInformation
[]
>
{
let
params
=
client
.
code2ProtocolConverter
.
asDocumentSymbolParams
(
document
);
let
params
:
DocumentColorParams
=
{
textDocument
:
client
.
code2ProtocolConverter
.
asTextDocumentIdentifier
(
document
)
};
return
client
.
sendRequest
(
DocumentColorRequest
.
type
,
params
).
then
(
symbols
=>
{
return
symbols
.
map
(
symbol
=>
{
let
range
=
client
.
protocol2CodeConverter
.
asRange
(
symbol
.
range
);
...
...
@@ -132,19 +130,19 @@ export function activate(context: ExtensionContext) {
});
});
},
provideColorPresentations
(
document
:
TextDocument
,
colorInfo
:
ColorInformation
):
ColorPresentation
[]
|
Thenable
<
ColorPresentation
[]
>
{
let
result
:
ColorPresentation
[]
=
[];
let
color
=
colorInfo
.
color
;
let
label
;
if
(
color
.
alpha
===
1
)
{
label
=
`#
${
_toTwoDigitHex
(
Math
.
round
(
color
.
red
*
255
))}${
_toTwoDigitHex
(
Math
.
round
(
color
.
green
*
255
))}${
_toTwoDigitHex
(
Math
.
round
(
color
.
blue
*
255
))}
`
;
}
else
{
label
=
`#
${
_toTwoDigitHex
(
Math
.
round
(
color
.
red
*
255
))}${
_toTwoDigitHex
(
Math
.
round
(
color
.
green
*
255
))}${
_toTwoDigitHex
(
Math
.
round
(
color
.
blue
*
255
))}${
_toTwoDigitHex
(
Math
.
round
(
color
.
alpha
*
255
))}
`
;
}
result
.
push
({
label
:
label
,
textEdit
:
new
TextEdit
(
colorInfo
.
range
,
label
)
});
return
result
;
provideColorPresentations
(
document
:
TextDocument
,
colorInfo
:
ColorInformation
):
Thenable
<
ColorPresentation
[]
>
{
let
params
:
ColorPresentationParams
=
{
textDocument
:
client
.
code2ProtocolConverter
.
asTextDocumentIdentifier
(
document
),
colorInfo
:
{
range
:
client
.
code2ProtocolConverter
.
asRange
(
colorInfo
.
range
),
color
:
colorInfo
.
color
}
};
return
client
.
sendRequest
(
ColorPresentationRequest
.
type
,
params
).
then
(
presentations
=>
{
return
presentations
.
map
(
p
=>
{
let
presentation
=
new
ColorPresentation
(
p
.
label
);
presentation
.
textEdit
=
p
.
textEdit
&&
client
.
protocol2CodeConverter
.
asTextEdit
(
p
.
textEdit
)
;
presentation
.
additionalTextEdits
=
p
.
additionalTextEdits
&&
client
.
protocol2CodeConverter
.
asTextEdits
(
p
.
additionalTextEdits
);
return
presentation
;
});
})
;
}
}));
});
...
...
extensions/json/npm-shrinkwrap.json
浏览文件 @
0e3d8542
...
...
@@ -13,24 +13,24 @@
"resolved"
:
"https://registry.npmjs.org/vscode-extension-telemetry/-/vscode-extension-telemetry-0.0.8.tgz"
},
"vscode-jsonrpc"
:
{
"version"
:
"3.
3.1
"
,
"from"
:
"vscode-jsonrpc@>=3.
3
.0 <4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.
3.1
.tgz"
"version"
:
"3.
4.0
"
,
"from"
:
"vscode-jsonrpc@>=3.
4
.0 <4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.
4.0
.tgz"
},
"vscode-languageclient"
:
{
"version"
:
"3.4.
0-next.17
"
,
"version"
:
"3.4.
2
"
,
"from"
:
"vscode-languageclient@next"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-3.4.
0-next.17
.tgz"
"resolved"
:
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-3.4.
2
.tgz"
},
"vscode-languageserver-protocol"
:
{
"version"
:
"3.
1.1
"
,
"from"
:
"vscode-languageserver-protocol@
>=3.1.1 <4.0.0
"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.
1.1
.tgz"
"version"
:
"3.
4.2
"
,
"from"
:
"vscode-languageserver-protocol@
3.4.2
"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.
4.2
.tgz"
},
"vscode-languageserver-types"
:
{
"version"
:
"3.
3
.0"
,
"from"
:
"vscode-languageserver-types@>=3.
3
.0 <4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.
3
.0.tgz"
"version"
:
"3.
4
.0"
,
"from"
:
"vscode-languageserver-types@>=3.
4
.0 <4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.
4
.0.tgz"
},
"vscode-nls"
:
{
"version"
:
"2.0.2"
,
...
...
@@ -43,4 +43,4 @@
"resolved"
:
"https://registry.npmjs.org/winreg/-/winreg-1.2.3.tgz"
}
}
}
}
\ No newline at end of file
extensions/json/package.json
浏览文件 @
0e3d8542
...
...
@@ -133,8 +133,8 @@
},
"dependencies"
:
{
"vscode-extension-telemetry"
:
"0.0.8"
,
"vscode-languageclient"
:
"
3.4.0-next.17
"
,
"vscode-languageserver-protocol"
:
"^3.
1.1
"
,
"vscode-languageclient"
:
"
^3.4.2
"
,
"vscode-languageserver-protocol"
:
"^3.
4.2
"
,
"vscode-nls"
:
"2.0.2"
},
"devDependencies"
:
{
...
...
extensions/json/server/npm-shrinkwrap.json
浏览文件 @
0e3d8542
...
...
@@ -43,29 +43,29 @@
"resolved"
:
"https://registry.npmjs.org/request-light/-/request-light-0.2.1.tgz"
},
"vscode-json-languageservice"
:
{
"version"
:
"2.0.
18
"
,
"version"
:
"2.0.
20
"
,
"from"
:
"vscode-json-languageservice@next"
,
"resolved"
:
"https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-2.0.
18
.tgz"
"resolved"
:
"https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-2.0.
20
.tgz"
},
"vscode-jsonrpc"
:
{
"version"
:
"3.
3.1
"
,
"from"
:
"vscode-jsonrpc@>=3.
3
.0 <4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.
3.1
.tgz"
"version"
:
"3.
4.0
"
,
"from"
:
"vscode-jsonrpc@>=3.
4
.0 <4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.
4.0
.tgz"
},
"vscode-languageserver"
:
{
"version"
:
"3.4.
0-next.6
"
,
"version"
:
"3.4.
2
"
,
"from"
:
"vscode-languageserver@next"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-3.4.
0-next.6
.tgz"
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-3.4.
2
.tgz"
},
"vscode-languageserver-protocol"
:
{
"version"
:
"3.
1.1
"
,
"from"
:
"vscode-languageserver-protocol@
>=3.1.1 <4.0.0
"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.
1.1
.tgz"
"version"
:
"3.
4.2
"
,
"from"
:
"vscode-languageserver-protocol@
3.4.2
"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.
4.2
.tgz"
},
"vscode-languageserver-types"
:
{
"version"
:
"3.
3
.0"
,
"from"
:
"vscode-languageserver-types@
>=3.0.3 <4.0
.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.
3
.0.tgz"
"version"
:
"3.
4
.0"
,
"from"
:
"vscode-languageserver-types@
3.4
.0"
,
"resolved"
:
"https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.
4
.0.tgz"
},
"vscode-nls"
:
{
"version"
:
"2.0.2"
,
...
...
extensions/json/server/package.json
浏览文件 @
0e3d8542
...
...
@@ -10,9 +10,10 @@
"dependencies"
:
{
"jsonc-parser"
:
"^1.0.0"
,
"request-light"
:
"^0.2.1"
,
"vscode-json-languageservice"
:
"^2.0.18"
,
"vscode-languageserver"
:
"3.4.0-next.6"
,
"vscode-languageserver-protocol"
:
"^3.1.1"
,
"vscode-json-languageservice"
:
"^2.0.20"
,
"vscode-languageserver"
:
"^3.4.2"
,
"vscode-languageserver-protocol"
:
"^3.4.2"
,
"vscode-languageserver-types"
:
"^3.4.0"
,
"vscode-nls"
:
"^2.0.2"
,
"vscode-uri"
:
"^1.0.1"
},
...
...
extensions/json/server/src/jsonServerMain.ts
浏览文件 @
0e3d8542
...
...
@@ -10,7 +10,7 @@ import {
DocumentRangeFormattingRequest
,
Disposable
,
ServerCapabilities
}
from
'
vscode-languageserver
'
;
import
{
DocumentColorRequest
,
ServerCapabilities
as
CPServerCapabilities
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
{
DocumentColorRequest
,
ServerCapabilities
as
CPServerCapabilities
,
ColorPresentationRequest
}
from
'
vscode-languageserver-protocol/lib/protocol.colorProvider.proposed
'
;
import
{
xhr
,
XHRResponse
,
configure
as
configureHttpRequests
,
getErrorStatusDescription
}
from
'
request-light
'
;
import
fs
=
require
(
'
fs
'
);
...
...
@@ -311,5 +311,14 @@ connection.onRequest(DocumentColorRequest.type, params => {
return
[];
});
connection
.
onRequest
(
ColorPresentationRequest
.
type
,
params
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
getColorPresentations
(
document
,
jsonDocument
,
params
.
colorInfo
);
}
return
[];
});
// Listen on the connection
connection
.
listen
();
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录