Add experimental VSCode api

This commit is contained in:
Kirill Bulatov 2021-02-09 12:39:40 +02:00 committed by Laurențiu Nicola
parent 9d473a0b9f
commit 55371be807
9 changed files with 136 additions and 618 deletions

View file

@ -244,16 +244,19 @@ pub struct InlayHintsParams {
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum InlayKind { pub enum InlayKind {
TypeHint, Other,
ParameterHint, Type,
ChainingHint, Parameter,
} }
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct InlayHint { pub struct InlayHint {
pub text: String,
pub range: Range, pub range: Range,
pub kind: InlayKind, pub kind: Option<InlayKind>,
pub label: String, pub description: Option<String>,
pub whitespace_before: Option<bool>,
pub whitespace_after: Option<bool>,
} }
pub enum Ssr {} pub enum Ssr {}

View file

@ -412,13 +412,16 @@ pub(crate) fn signature_help(
pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ext::InlayHint { pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ext::InlayHint {
lsp_ext::InlayHint { lsp_ext::InlayHint {
label: inlay_hint.label.to_string(), text: inlay_hint.label.to_string(),
range: range(line_index, inlay_hint.range), range: range(line_index, inlay_hint.range),
kind: match inlay_hint.kind { kind: Some(match inlay_hint.kind {
InlayKind::ParameterHint => lsp_ext::InlayKind::ParameterHint, InlayKind::ParameterHint => lsp_ext::InlayKind::Parameter,
InlayKind::TypeHint => lsp_ext::InlayKind::TypeHint, InlayKind::TypeHint => lsp_ext::InlayKind::Type,
InlayKind::ChainingHint => lsp_ext::InlayKind::ChainingHint, InlayKind::ChainingHint => lsp_ext::InlayKind::Other,
}, }),
description: Some("test description".to_string()),
whitespace_before: Some(true),
whitespace_after: Some(true),
} }
} }

View file

@ -3,3 +3,5 @@ node_modules
server server
.vscode-test/ .vscode-test/
*.vsix *.vsix
bundle
vscode.proposed.d.ts

View file

@ -24,7 +24,8 @@
"tslib": "^2.3.0", "tslib": "^2.3.0",
"typescript": "^4.5.5", "typescript": "^4.5.5",
"typescript-formatter": "^7.2.2", "typescript-formatter": "^7.2.2",
"vsce": "^2.6.3" "vsce": "^2.6.7",
"vscode-dts": "^0.3.1"
}, },
"engines": { "engines": {
"vscode": "^1.63.0" "vscode": "^1.63.0"
@ -1543,84 +1544,6 @@
"esbuild-windows-arm64": "0.14.12" "esbuild-windows-arm64": "0.14.12"
} }
}, },
"node_modules/esbuild-android-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.12.tgz",
"integrity": "sha512-eO4JHwnTeJq1/xC9K0FdHNEYztwT0HaWHnOzR5kXKwJxHatxDNZ+lCHOSxMzh9uVSmnA8YwdSiXPWbwTlWZVrw==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"android"
]
},
"node_modules/esbuild-darwin-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.12.tgz",
"integrity": "sha512-LyZ81assnJWhq2IxKEVipwddKlXLTubbz/IObyKOm5cWS9jQCpuwQey2PpzroWSiy7QLGV8XCGWY5b8U8fsmWA==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"darwin"
]
},
"node_modules/esbuild-darwin-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.12.tgz",
"integrity": "sha512-jj27iSbDS4KlftN1PHHNiTrtXPQIk11J/qpQiQLwKJpeEMNeJUBfQlS7X7dXgFFMxV0rNtcRl8AimEFl+qEMRQ==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"darwin"
]
},
"node_modules/esbuild-freebsd-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.12.tgz",
"integrity": "sha512-RnTty09bA8Ts/eWnrJsYiE2dFM6ZseKYQ/7QCM5QYphU6GbifooO9oGjc/UE3Sg8R58yZVO15vnIV0i+kTgDOw==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"freebsd"
]
},
"node_modules/esbuild-freebsd-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.12.tgz",
"integrity": "sha512-AvAQoEgsHE53hucgoVWdHnXJBl0r9W/7eUCaBvpcgYu3W/EbPZ26VnZwfSXLpk0Pf3t7o6SRwrU+KDTKPscDTw==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"freebsd"
]
},
"node_modules/esbuild-linux-32": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.12.tgz",
"integrity": "sha512-na4I5i2c9ACPuglfYmrnJ6qGQnFJb59dFjyFk5OHTCtoKCq3lXbGHrvYa+3sYlOrRax1kYuRDRGse7YsDLbr3Q==",
"cpu": [
"ia32"
],
"dev": true,
"optional": true,
"os": [
"linux"
]
},
"node_modules/esbuild-linux-64": { "node_modules/esbuild-linux-64": {
"version": "0.14.12", "version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.12.tgz", "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.12.tgz",
@ -1634,149 +1557,6 @@
"linux" "linux"
] ]
}, },
"node_modules/esbuild-linux-arm": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.12.tgz",
"integrity": "sha512-tD4q/zVUeYkThGehYAJQElo80+ysxvq5vpd2QvykDp4hvIidEUJu2hf+NzG5OuMJSQJmAeAWPrkFOXN+6di9cA==",
"cpu": [
"arm"
],
"dev": true,
"optional": true,
"os": [
"linux"
]
},
"node_modules/esbuild-linux-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.12.tgz",
"integrity": "sha512-i1/ikCl9gG9yx6QuI+8yJMk9XHUu8ekIQOo6cex2pDqXY5KVHSXDTAT4FDWOd5YXQ1QTjneBAQHcKGft4pd6PQ==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"linux"
]
},
"node_modules/esbuild-linux-mips64le": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.12.tgz",
"integrity": "sha512-+/a6/tiKUCENep8ryUR75Jba4znG51Sb75OzKT6phZFEkB7fao4+GZD39Zxx3EaaA5OC10MsJPjJMFrn0dMusg==",
"cpu": [
"mips64el"
],
"dev": true,
"optional": true,
"os": [
"linux"
]
},
"node_modules/esbuild-linux-ppc64le": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.12.tgz",
"integrity": "sha512-SD7e2VLza/cEU2qKuD18Ibt1V0h3TUuerC1Mp3jRJ4RRGXWAyUt4gUpqKSiB7R0rHe6LWECdLbeVFAuGEntCeA==",
"cpu": [
"ppc64"
],
"dev": true,
"optional": true,
"os": [
"linux"
]
},
"node_modules/esbuild-linux-s390x": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.12.tgz",
"integrity": "sha512-KZmjYgAvYUpPBG0v6xv8qCngbfcRKC2AdYx3H3j3VqJfICgjt5XYsyG7ntWdc8Rdw9jZxr9sni6othy2Rp/T+A==",
"cpu": [
"s390x"
],
"dev": true,
"optional": true,
"os": [
"linux"
]
},
"node_modules/esbuild-netbsd-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.12.tgz",
"integrity": "sha512-dG+hbCIJC65fHqzkTEYbrPSYG3m8pEaI9A1VDtqHfV13Oiw9/tua1odd47iwoWvTyurErb49wanHsIAKb8/2oQ==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"netbsd"
]
},
"node_modules/esbuild-openbsd-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.12.tgz",
"integrity": "sha512-W3SwxnMjJR3HtBD0aij5WPd0ow2bRB5BsW6FjhN7FgwDBQ+jgniFs1dq54HOkjQ2qBJrt8JvPDFAxacWjdD6Jw==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"openbsd"
]
},
"node_modules/esbuild-sunos-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.12.tgz",
"integrity": "sha512-jU/IcTFwvUtt21wOmqKJrevyHQ5XRfiCdFbPie4wsYr8VFcPZZsz18A9lcoI8gZdrF/8pBdD0V+L2UuUY0KsGg==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"sunos"
]
},
"node_modules/esbuild-windows-32": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.12.tgz",
"integrity": "sha512-6luae9cmTB0rSPMCQFWMgf0SLNZ9hxusoS0poVEUHJf3n8bW6wgdyLE2xfYcEcXPMsjAt2e71/etkpqlFxeuYg==",
"cpu": [
"ia32"
],
"dev": true,
"optional": true,
"os": [
"win32"
]
},
"node_modules/esbuild-windows-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.12.tgz",
"integrity": "sha512-CdCXvME/7s0uMt+4rYd8d5roHJJ5k2VDOzWaOMWExjroet+nSSZngfLpxI5St+28lXLeBorUxeBS+p1qcfEDfw==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"win32"
]
},
"node_modules/esbuild-windows-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.12.tgz",
"integrity": "sha512-vNuLQh/MpYDepK0GNpEWHy0Kn7Jf3Shz/Xetf8hUIc31jgCR1qbLVLDf3ckQdanD2U430YZupOGtEZKRwno79w==",
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"win32"
]
},
"node_modules/escape-string-regexp": { "node_modules/escape-string-regexp": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz",
@ -2564,6 +2344,15 @@
"prebuild-install": "^6.0.0" "prebuild-install": "^6.0.0"
} }
}, },
"node_modules/kleur": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/leven": { "node_modules/leven": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz",
@ -2987,6 +2776,19 @@
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
"dev": true "dev": true
}, },
"node_modules/prompts": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
"integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==",
"dev": true,
"dependencies": {
"kleur": "^3.0.3",
"sisteransi": "^1.0.5"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/pseudomap": { "node_modules/pseudomap": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
@ -3298,6 +3100,12 @@
"simple-concat": "^1.0.0" "simple-concat": "^1.0.0"
} }
}, },
"node_modules/sisteransi": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
"dev": true
},
"node_modules/slash": { "node_modules/slash": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
@ -3763,6 +3571,20 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/vscode-dts": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/vscode-dts/-/vscode-dts-0.3.3.tgz",
"integrity": "sha512-JfOsWL0NvfVw0UF9bcTjlv1Onz3Ted7cgpPWKWMnHGB+72t/tn8WFDeKLZO42l2k9KJq/NGS9rFC5gZbyI4FTg==",
"dev": true,
"dependencies": {
"minimist": "^1.2.0",
"prompts": "^2.1.0",
"rimraf": "^3.0.0"
},
"bin": {
"vscode-dts": "index.js"
}
},
"node_modules/vscode-jsonrpc": { "node_modules/vscode-jsonrpc": {
"version": "8.0.0-next.5", "version": "8.0.0-next.5",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.5.tgz", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.5.tgz",
@ -5002,48 +4824,6 @@
"esbuild-windows-arm64": "0.14.12" "esbuild-windows-arm64": "0.14.12"
} }
}, },
"esbuild-android-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.12.tgz",
"integrity": "sha512-eO4JHwnTeJq1/xC9K0FdHNEYztwT0HaWHnOzR5kXKwJxHatxDNZ+lCHOSxMzh9uVSmnA8YwdSiXPWbwTlWZVrw==",
"dev": true,
"optional": true
},
"esbuild-darwin-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.12.tgz",
"integrity": "sha512-LyZ81assnJWhq2IxKEVipwddKlXLTubbz/IObyKOm5cWS9jQCpuwQey2PpzroWSiy7QLGV8XCGWY5b8U8fsmWA==",
"dev": true,
"optional": true
},
"esbuild-darwin-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.12.tgz",
"integrity": "sha512-jj27iSbDS4KlftN1PHHNiTrtXPQIk11J/qpQiQLwKJpeEMNeJUBfQlS7X7dXgFFMxV0rNtcRl8AimEFl+qEMRQ==",
"dev": true,
"optional": true
},
"esbuild-freebsd-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.12.tgz",
"integrity": "sha512-RnTty09bA8Ts/eWnrJsYiE2dFM6ZseKYQ/7QCM5QYphU6GbifooO9oGjc/UE3Sg8R58yZVO15vnIV0i+kTgDOw==",
"dev": true,
"optional": true
},
"esbuild-freebsd-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.12.tgz",
"integrity": "sha512-AvAQoEgsHE53hucgoVWdHnXJBl0r9W/7eUCaBvpcgYu3W/EbPZ26VnZwfSXLpk0Pf3t7o6SRwrU+KDTKPscDTw==",
"dev": true,
"optional": true
},
"esbuild-linux-32": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.12.tgz",
"integrity": "sha512-na4I5i2c9ACPuglfYmrnJ6qGQnFJb59dFjyFk5OHTCtoKCq3lXbGHrvYa+3sYlOrRax1kYuRDRGse7YsDLbr3Q==",
"dev": true,
"optional": true
},
"esbuild-linux-64": { "esbuild-linux-64": {
"version": "0.14.12", "version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.12.tgz", "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.12.tgz",
@ -5051,83 +4831,6 @@
"dev": true, "dev": true,
"optional": true "optional": true
}, },
"esbuild-linux-arm": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.12.tgz",
"integrity": "sha512-tD4q/zVUeYkThGehYAJQElo80+ysxvq5vpd2QvykDp4hvIidEUJu2hf+NzG5OuMJSQJmAeAWPrkFOXN+6di9cA==",
"dev": true,
"optional": true
},
"esbuild-linux-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.12.tgz",
"integrity": "sha512-i1/ikCl9gG9yx6QuI+8yJMk9XHUu8ekIQOo6cex2pDqXY5KVHSXDTAT4FDWOd5YXQ1QTjneBAQHcKGft4pd6PQ==",
"dev": true,
"optional": true
},
"esbuild-linux-mips64le": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.12.tgz",
"integrity": "sha512-+/a6/tiKUCENep8ryUR75Jba4znG51Sb75OzKT6phZFEkB7fao4+GZD39Zxx3EaaA5OC10MsJPjJMFrn0dMusg==",
"dev": true,
"optional": true
},
"esbuild-linux-ppc64le": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.12.tgz",
"integrity": "sha512-SD7e2VLza/cEU2qKuD18Ibt1V0h3TUuerC1Mp3jRJ4RRGXWAyUt4gUpqKSiB7R0rHe6LWECdLbeVFAuGEntCeA==",
"dev": true,
"optional": true
},
"esbuild-linux-s390x": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.12.tgz",
"integrity": "sha512-KZmjYgAvYUpPBG0v6xv8qCngbfcRKC2AdYx3H3j3VqJfICgjt5XYsyG7ntWdc8Rdw9jZxr9sni6othy2Rp/T+A==",
"dev": true,
"optional": true
},
"esbuild-netbsd-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.12.tgz",
"integrity": "sha512-dG+hbCIJC65fHqzkTEYbrPSYG3m8pEaI9A1VDtqHfV13Oiw9/tua1odd47iwoWvTyurErb49wanHsIAKb8/2oQ==",
"dev": true,
"optional": true
},
"esbuild-openbsd-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.12.tgz",
"integrity": "sha512-W3SwxnMjJR3HtBD0aij5WPd0ow2bRB5BsW6FjhN7FgwDBQ+jgniFs1dq54HOkjQ2qBJrt8JvPDFAxacWjdD6Jw==",
"dev": true,
"optional": true
},
"esbuild-sunos-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.12.tgz",
"integrity": "sha512-jU/IcTFwvUtt21wOmqKJrevyHQ5XRfiCdFbPie4wsYr8VFcPZZsz18A9lcoI8gZdrF/8pBdD0V+L2UuUY0KsGg==",
"dev": true,
"optional": true
},
"esbuild-windows-32": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.12.tgz",
"integrity": "sha512-6luae9cmTB0rSPMCQFWMgf0SLNZ9hxusoS0poVEUHJf3n8bW6wgdyLE2xfYcEcXPMsjAt2e71/etkpqlFxeuYg==",
"dev": true,
"optional": true
},
"esbuild-windows-64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.12.tgz",
"integrity": "sha512-CdCXvME/7s0uMt+4rYd8d5roHJJ5k2VDOzWaOMWExjroet+nSSZngfLpxI5St+28lXLeBorUxeBS+p1qcfEDfw==",
"dev": true,
"optional": true
},
"esbuild-windows-arm64": {
"version": "0.14.12",
"resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.12.tgz",
"integrity": "sha512-vNuLQh/MpYDepK0GNpEWHy0Kn7Jf3Shz/Xetf8hUIc31jgCR1qbLVLDf3ckQdanD2U430YZupOGtEZKRwno79w==",
"dev": true,
"optional": true
},
"escape-string-regexp": { "escape-string-regexp": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz",
@ -5739,6 +5442,12 @@
"prebuild-install": "^6.0.0" "prebuild-install": "^6.0.0"
} }
}, },
"kleur": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==",
"dev": true
},
"leven": { "leven": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz",
@ -6081,6 +5790,16 @@
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
"dev": true "dev": true
}, },
"prompts": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
"integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==",
"dev": true,
"requires": {
"kleur": "^3.0.3",
"sisteransi": "^1.0.5"
}
},
"pseudomap": { "pseudomap": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
@ -6300,6 +6019,12 @@
"simple-concat": "^1.0.0" "simple-concat": "^1.0.0"
} }
}, },
"sisteransi": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
"dev": true
},
"slash": { "slash": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
@ -6670,6 +6395,17 @@
} }
} }
}, },
"vscode-dts": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/vscode-dts/-/vscode-dts-0.3.3.tgz",
"integrity": "sha512-JfOsWL0NvfVw0UF9bcTjlv1Onz3Ted7cgpPWKWMnHGB+72t/tn8WFDeKLZO42l2k9KJq/NGS9rFC5gZbyI4FTg==",
"dev": true,
"requires": {
"minimist": "^1.2.0",
"prompts": "^2.1.0",
"rimraf": "^3.0.0"
}
},
"vscode-jsonrpc": { "vscode-jsonrpc": {
"version": "8.0.0-next.5", "version": "8.0.0-next.5",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.5.tgz", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.5.tgz",

View file

@ -51,7 +51,8 @@
"tslib": "^2.3.0", "tslib": "^2.3.0",
"typescript": "^4.5.5", "typescript": "^4.5.5",
"typescript-formatter": "^7.2.2", "typescript-formatter": "^7.2.2",
"vsce": "^2.6.7" "vsce": "^2.6.7",
"vscode-dts": "^0.3.1"
}, },
"activationEvents": [ "activationEvents": [
"onLanguage:rust", "onLanguage:rust",

View file

@ -77,8 +77,7 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
client.handleFailedRequest( client.handleFailedRequest(
lc.HoverRequest.type, lc.HoverRequest.type,
token, token,
error, error
null
); );
return Promise.resolve(null); return Promise.resolve(null);
} }

View file

@ -1,267 +1,54 @@
import * as lc from "vscode-languageclient";
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as ra from './lsp_ext'; import * as ra from './lsp_ext';
import { Ctx, Disposable } from './ctx'; import { Ctx, Disposable } from './ctx';
import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util'; import { sendRequestWithRetry, isRustDocument } from './util';
interface InlayHintStyle {
decorationType: vscode.TextEditorDecorationType;
toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions;
};
interface InlayHintsStyles {
typeHints: InlayHintStyle;
paramHints: InlayHintStyle;
chainingHints: InlayHintStyle;
}
export function activateInlayHints(ctx: Ctx) { export function activateInlayHints(ctx: Ctx) {
const maybeUpdater = { const maybeUpdater = {
updater: null as null | HintsUpdater, hintsProvider: null as Disposable | null,
updateHintsEventEmitter: new vscode.EventEmitter<void>(),
async onConfigChange() { async onConfigChange() {
this.dispose();
const anyEnabled = ctx.config.inlayHints.typeHints const anyEnabled = ctx.config.inlayHints.typeHints
|| ctx.config.inlayHints.parameterHints || ctx.config.inlayHints.parameterHints
|| ctx.config.inlayHints.chainingHints; || ctx.config.inlayHints.chainingHints;
const enabled = ctx.config.inlayHints.enable && anyEnabled; const enabled = ctx.config.inlayHints.enable && anyEnabled;
if (!enabled) return;
if (!enabled) return this.dispose(); const event = this.updateHintsEventEmitter.event;
this.hintsProvider = vscode.languages.registerInlayHintsProvider({ scheme: 'file', language: 'rust' }, new class implements vscode.InlayHintsProvider {
await sleep(100); onDidChangeInlayHints = event;
if (this.updater) { async provideInlayHints(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken): Promise<vscode.InlayHint[]> {
this.updater.updateInlayHintsStyles(); const request = { textDocument: { uri: document.uri.toString() }, range: { start: range.start, end: range.end } };
this.updater.syncCacheAndRenderHints(); const hints = await sendRequestWithRetry(ctx.client, ra.inlayHints, request, token).catch(_ => null)
if (hints == null) {
return [];
} else { } else {
this.updater = new HintsUpdater(ctx); return hints;
} }
}
});
}, },
dispose() {
this.updater?.dispose();
this.updater = null;
}
};
ctx.pushCleanup(maybeUpdater);
vscode.workspace.onDidChangeConfiguration(
maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions
);
maybeUpdater.onConfigChange().catch(console.error);
}
function createHintStyle(hintKind: "type" | "parameter" | "chaining", smallerHints: boolean): InlayHintStyle {
// U+200C is a zero-width non-joiner to prevent the editor from forming a ligature
// between code and type hints
const [pos, render] = ({
type: ["after", (label: string) => `\u{200c}: ${label}`],
parameter: ["before", (label: string) => `${label}: `],
chaining: ["after", (label: string) => `\u{200c}: ${label}`],
} as const)[hintKind];
const fg = new vscode.ThemeColor(`rust_analyzer.inlayHints.foreground.${hintKind}Hints`);
const bg = new vscode.ThemeColor(`rust_analyzer.inlayHints.background.${hintKind}Hints`);
return {
decorationType: vscode.window.createTextEditorDecorationType({
[pos]: {
color: fg,
backgroundColor: bg,
fontStyle: "normal",
fontWeight: "normal",
textDecoration: smallerHints ? ";font-size:smaller" : "none",
},
}),
toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions {
return {
range: conv.asRange(hint.range),
renderOptions: { [pos]: { contentText: render(hint.label) } }
};
}
};
}
const smallHintsStyles = {
typeHints: createHintStyle("type", true),
paramHints: createHintStyle("parameter", true),
chainingHints: createHintStyle("chaining", true),
};
const biggerHintsStyles = {
typeHints: createHintStyle("type", false),
paramHints: createHintStyle("parameter", false),
chainingHints: createHintStyle("chaining", false),
};
class HintsUpdater implements Disposable {
private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile
private readonly disposables: Disposable[] = [];
private pendingDisposeDecorations: undefined | InlayHintsStyles = undefined;
private inlayHintsStyles!: InlayHintsStyles;
constructor(private readonly ctx: Ctx) {
vscode.window.onDidChangeVisibleTextEditors(
this.onDidChangeVisibleTextEditors,
this,
this.disposables
);
vscode.workspace.onDidChangeTextDocument(
this.onDidChangeTextDocument,
this,
this.disposables
);
// Set up initial cache shape
ctx.visibleRustEditors.forEach(editor => this.sourceFiles.set(
editor.document.uri.toString(),
{
document: editor.document,
inlaysRequest: null,
cachedDecorations: null
}
));
this.updateInlayHintsStyles();
this.syncCacheAndRenderHints();
}
dispose() {
this.sourceFiles.forEach(file => file.inlaysRequest?.cancel());
this.ctx.visibleRustEditors.forEach(editor => this.renderDecorations(editor, { param: [], type: [], chaining: [] }));
this.disposables.forEach(d => d.dispose());
}
onDidChangeTextDocument({ contentChanges, document }: vscode.TextDocumentChangeEvent) { onDidChangeTextDocument({ contentChanges, document }: vscode.TextDocumentChangeEvent) {
if (contentChanges.length === 0 || !isRustDocument(document)) return; if (contentChanges.length === 0 || !isRustDocument(document)) return;
this.syncCacheAndRenderHints(); this.updateHintsEventEmitter.fire();
},
dispose() {
this.hintsProvider?.dispose();
this.hintsProvider = null;
this.updateHintsEventEmitter.dispose();
},
} }
updateInlayHintsStyles() { ctx.pushCleanup(maybeUpdater);
const inlayHintsStyles = this.ctx.config.inlayHints.smallerHints ? smallHintsStyles : biggerHintsStyles;
if (inlayHintsStyles !== this.inlayHintsStyles) { vscode.workspace.onDidChangeConfiguration(maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions);
this.pendingDisposeDecorations = this.inlayHintsStyles; vscode.workspace.onDidChangeTextDocument(maybeUpdater.onDidChangeTextDocument, maybeUpdater, ctx.subscriptions);
this.inlayHintsStyles = inlayHintsStyles;
}
}
syncCacheAndRenderHints() { maybeUpdater.onConfigChange().catch(console.error);
this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => {
if (!hints) return;
file.cachedDecorations = this.hintsToDecorations(hints);
for (const editor of this.ctx.visibleRustEditors) {
if (editor.document.uri.toString() === uri) {
this.renderDecorations(editor, file.cachedDecorations);
}
}
}));
}
onDidChangeVisibleTextEditors() {
const newSourceFiles = new Map<string, RustSourceFile>();
// Rerendering all, even up-to-date editors for simplicity
this.ctx.visibleRustEditors.forEach(async editor => {
const uri = editor.document.uri.toString();
const file = this.sourceFiles.get(uri) ?? {
document: editor.document,
inlaysRequest: null,
cachedDecorations: null
};
newSourceFiles.set(uri, file);
// No text documents changed, so we may try to use the cache
if (!file.cachedDecorations) {
const hints = await this.fetchHints(file);
if (!hints) return;
file.cachedDecorations = this.hintsToDecorations(hints);
}
this.renderDecorations(editor, file.cachedDecorations);
});
// Cancel requests for no longer visible (disposed) source files
this.sourceFiles.forEach((file, uri) => {
if (!newSourceFiles.has(uri)) file.inlaysRequest?.cancel();
});
this.sourceFiles = newSourceFiles;
}
private renderDecorations(editor: RustEditor, decorations: InlaysDecorations) {
const { typeHints, paramHints, chainingHints } = this.inlayHintsStyles;
if (this.pendingDisposeDecorations !== undefined) {
const { typeHints, paramHints, chainingHints } = this.pendingDisposeDecorations;
editor.setDecorations(typeHints.decorationType, []);
editor.setDecorations(paramHints.decorationType, []);
editor.setDecorations(chainingHints.decorationType, []);
}
editor.setDecorations(typeHints.decorationType, decorations.type);
editor.setDecorations(paramHints.decorationType, decorations.param);
editor.setDecorations(chainingHints.decorationType, decorations.chaining);
}
private hintsToDecorations(hints: ra.InlayHint[]): InlaysDecorations {
const { typeHints, paramHints, chainingHints } = this.inlayHintsStyles;
const decorations: InlaysDecorations = { type: [], param: [], chaining: [] };
const conv = this.ctx.client.protocol2CodeConverter;
for (const hint of hints) {
switch (hint.kind) {
case ra.InlayHint.Kind.TypeHint: {
decorations.type.push(typeHints.toDecoration(hint, conv));
continue;
}
case ra.InlayHint.Kind.ParamHint: {
decorations.param.push(paramHints.toDecoration(hint, conv));
continue;
}
case ra.InlayHint.Kind.ChainingHint: {
decorations.chaining.push(chainingHints.toDecoration(hint, conv));
continue;
}
}
}
return decorations;
}
private async fetchHints(file: RustSourceFile): Promise<null | ra.InlayHint[]> {
file.inlaysRequest?.cancel();
const tokenSource = new vscode.CancellationTokenSource();
file.inlaysRequest = tokenSource;
const request = { textDocument: { uri: file.document.uri.toString() } };
return sendRequestWithRetry(this.ctx.client, ra.inlayHints, request, tokenSource.token)
.catch(_ => null)
.finally(() => {
if (file.inlaysRequest === tokenSource) {
file.inlaysRequest = null;
}
});
}
}
interface InlaysDecorations {
type: vscode.DecorationOptions[];
param: vscode.DecorationOptions[];
chaining: vscode.DecorationOptions[];
}
interface RustSourceFile {
/**
* Source of the token to cancel in-flight inlay hints request if any.
*/
inlaysRequest: null | vscode.CancellationTokenSource;
/**
* Last applied decorations.
*/
cachedDecorations: null | InlaysDecorations;
document: RustDocument;
} }

View file

@ -2,6 +2,7 @@
* This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations. * This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations.
*/ */
import { InlayHint } from "vscode";
import * as lc from "vscode-languageclient"; import * as lc from "vscode-languageclient";
export interface AnalyzerStatusParams { export interface AnalyzerStatusParams {
@ -99,24 +100,9 @@ export interface TestInfo {
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>("rust-analyzer/relatedTests"); export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>("rust-analyzer/relatedTests");
export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;
export namespace InlayHint {
export const enum Kind {
TypeHint = "TypeHint",
ParamHint = "ParameterHint",
ChainingHint = "ChainingHint",
}
interface Common {
range: lc.Range;
label: string;
}
export type TypeHint = Common & { kind: Kind.TypeHint };
export type ParamHint = Common & { kind: Kind.ParamHint };
export type ChainingHint = Common & { kind: Kind.ChainingHint };
}
export interface InlayHintsParams { export interface InlayHintsParams {
textDocument: lc.TextDocumentIdentifier; textDocument: lc.TextDocumentIdentifier;
range: lc.Range,
} }
export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void>("rust-analyzer/inlayHints"); export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void>("rust-analyzer/inlayHints");

View file

@ -22,6 +22,7 @@
], ],
"include": [ "include": [
"src", "src",
"tests" "tests",
"vscode.proposed.d.ts"
] ]
} }