From 55371be807bf5eb5d526658d77084230213881fb Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 9 Feb 2021 12:39:40 +0200 Subject: [PATCH 01/16] Add experimental VSCode api --- crates/rust-analyzer/src/lsp_ext.rs | 13 +- crates/rust-analyzer/src/to_proto.rs | 15 +- editors/code/.gitignore | 2 + editors/code/package-lock.json | 418 +++++---------------------- editors/code/package.json | 3 +- editors/code/src/client.ts | 3 +- editors/code/src/inlay_hints.ts | 279 +++--------------- editors/code/src/lsp_ext.ts | 18 +- editors/code/tsconfig.json | 3 +- 9 files changed, 136 insertions(+), 618 deletions(-) diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index ea98d0993529..7e7f96da21e1 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -244,16 +244,19 @@ pub struct InlayHintsParams { #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] pub enum InlayKind { - TypeHint, - ParameterHint, - ChainingHint, + Other, + Type, + Parameter, } #[derive(Debug, Deserialize, Serialize)] pub struct InlayHint { + pub text: String, pub range: Range, - pub kind: InlayKind, - pub label: String, + pub kind: Option, + pub description: Option, + pub whitespace_before: Option, + pub whitespace_after: Option, } pub enum Ssr {} diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index f0de166d8b59..a5d7b3a86f78 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -412,13 +412,16 @@ pub(crate) fn signature_help( pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: 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), - kind: match inlay_hint.kind { - InlayKind::ParameterHint => lsp_ext::InlayKind::ParameterHint, - InlayKind::TypeHint => lsp_ext::InlayKind::TypeHint, - InlayKind::ChainingHint => lsp_ext::InlayKind::ChainingHint, - }, + kind: Some(match inlay_hint.kind { + InlayKind::ParameterHint => lsp_ext::InlayKind::Parameter, + InlayKind::TypeHint => lsp_ext::InlayKind::Type, + InlayKind::ChainingHint => lsp_ext::InlayKind::Other, + }), + description: Some("test description".to_string()), + whitespace_before: Some(true), + whitespace_after: Some(true), } } diff --git a/editors/code/.gitignore b/editors/code/.gitignore index 3acb6b3f6202..2c975a947eb3 100644 --- a/editors/code/.gitignore +++ b/editors/code/.gitignore @@ -3,3 +3,5 @@ node_modules server .vscode-test/ *.vsix +bundle +vscode.proposed.d.ts diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 1f0c97ad270b..313da64430ef 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json @@ -24,7 +24,8 @@ "tslib": "^2.3.0", "typescript": "^4.5.5", "typescript-formatter": "^7.2.2", - "vsce": "^2.6.3" + "vsce": "^2.6.7", + "vscode-dts": "^0.3.1" }, "engines": { "vscode": "^1.63.0" @@ -1543,84 +1544,6 @@ "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": { "version": "0.14.12", "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.12.tgz", @@ -1634,149 +1557,6 @@ "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": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -2564,6 +2344,15 @@ "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": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -2987,6 +2776,19 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "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": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -3298,6 +3100,12 @@ "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": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -3763,6 +3571,20 @@ "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": { "version": "8.0.0-next.5", "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-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": { "version": "0.14.12", "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.12.tgz", @@ -5051,83 +4831,6 @@ "dev": 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": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -5739,6 +5442,12 @@ "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": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -6081,6 +5790,16 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "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": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -6300,6 +6019,12 @@ "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": { "version": "3.0.0", "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": { "version": "8.0.0-next.5", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.5.tgz", diff --git a/editors/code/package.json b/editors/code/package.json index 1252752a9ae0..3ddae8109efe 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -51,7 +51,8 @@ "tslib": "^2.3.0", "typescript": "^4.5.5", "typescript-formatter": "^7.2.2", - "vsce": "^2.6.7" + "vsce": "^2.6.7", + "vscode-dts": "^0.3.1" }, "activationEvents": [ "onLanguage:rust", diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 26567c6df3c0..4e5d7bf8e8b5 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -77,8 +77,7 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv: client.handleFailedRequest( lc.HoverRequest.type, token, - error, - null + error ); return Promise.resolve(null); } diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index c23d6f7384b9..af45d7032de9 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -1,267 +1,54 @@ -import * as lc from "vscode-languageclient"; import * as vscode from 'vscode'; import * as ra from './lsp_ext'; import { Ctx, Disposable } from './ctx'; -import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util'; - -interface InlayHintStyle { - decorationType: vscode.TextEditorDecorationType; - toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions; -}; - -interface InlayHintsStyles { - typeHints: InlayHintStyle; - paramHints: InlayHintStyle; - chainingHints: InlayHintStyle; -} - +import { sendRequestWithRetry, isRustDocument } from './util'; export function activateInlayHints(ctx: Ctx) { const maybeUpdater = { - updater: null as null | HintsUpdater, + hintsProvider: null as Disposable | null, + updateHintsEventEmitter: new vscode.EventEmitter(), + async onConfigChange() { + this.dispose(); + const anyEnabled = ctx.config.inlayHints.typeHints || ctx.config.inlayHints.parameterHints || ctx.config.inlayHints.chainingHints; const enabled = ctx.config.inlayHints.enable && anyEnabled; + if (!enabled) return; + + const event = this.updateHintsEventEmitter.event; + this.hintsProvider = vscode.languages.registerInlayHintsProvider({ scheme: 'file', language: 'rust' }, new class implements vscode.InlayHintsProvider { + onDidChangeInlayHints = event; + async provideInlayHints(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken): Promise { + const request = { textDocument: { uri: document.uri.toString() }, range: { start: range.start, end: range.end } }; + const hints = await sendRequestWithRetry(ctx.client, ra.inlayHints, request, token).catch(_ => null) + if (hints == null) { + return []; + } else { + return hints; + } + } + }); + }, - if (!enabled) return this.dispose(); - - await sleep(100); - if (this.updater) { - this.updater.updateInlayHintsStyles(); - this.updater.syncCacheAndRenderHints(); - } else { - this.updater = new HintsUpdater(ctx); - } + onDidChangeTextDocument({ contentChanges, document }: vscode.TextDocumentChangeEvent) { + if (contentChanges.length === 0 || !isRustDocument(document)) return; + this.updateHintsEventEmitter.fire(); }, + dispose() { - this.updater?.dispose(); - this.updater = null; - } - }; + this.hintsProvider?.dispose(); + this.hintsProvider = null; + this.updateHintsEventEmitter.dispose(); + }, + } ctx.pushCleanup(maybeUpdater); - vscode.workspace.onDidChangeConfiguration( - maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions - ); + vscode.workspace.onDidChangeConfiguration(maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions); + vscode.workspace.onDidChangeTextDocument(maybeUpdater.onDidChangeTextDocument, 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(); // 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) { - if (contentChanges.length === 0 || !isRustDocument(document)) return; - this.syncCacheAndRenderHints(); - } - - updateInlayHintsStyles() { - const inlayHintsStyles = this.ctx.config.inlayHints.smallerHints ? smallHintsStyles : biggerHintsStyles; - - if (inlayHintsStyles !== this.inlayHintsStyles) { - this.pendingDisposeDecorations = this.inlayHintsStyles; - this.inlayHintsStyles = inlayHintsStyles; - } - } - - syncCacheAndRenderHints() { - 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(); - - // 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 { - 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; -} diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 9248bd1b6f6b..03cd15200ba3 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -2,6 +2,7 @@ * This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations. */ +import { InlayHint } from "vscode"; import * as lc from "vscode-languageclient"; export interface AnalyzerStatusParams { @@ -99,24 +100,9 @@ export interface TestInfo { export const relatedTests = new lc.RequestType("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 { textDocument: lc.TextDocumentIdentifier; + range: lc.Range, } export const inlayHints = new lc.RequestType("rust-analyzer/inlayHints"); diff --git a/editors/code/tsconfig.json b/editors/code/tsconfig.json index 7c4fbd21ebec..46fd163dcb12 100644 --- a/editors/code/tsconfig.json +++ b/editors/code/tsconfig.json @@ -22,6 +22,7 @@ ], "include": [ "src", - "tests" + "tests", + "vscode.proposed.d.ts" ] } From 0f396d670bc1593b6688d5cf7595f1e821c8323d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 9 Feb 2022 19:13:04 +0200 Subject: [PATCH 02/16] Bump deps --- editors/code/package-lock.json | 81 +++++++++++++++++----------------- editors/code/package.json | 15 ++++--- editors/code/tsconfig.json | 2 +- 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 313da64430ef..0d6e3c55cd2a 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json @@ -7,15 +7,16 @@ "": { "name": "rust-analyzer", "version": "0.4.0-dev", + "hasInstallScript": true, "license": "MIT OR Apache-2.0", "dependencies": { "d3": "^7.3.0", "d3-graphviz": "^4.0.0", - "vscode-languageclient": "8.0.0-next.8" + "vscode-languageclient": "8.0.0-next.12" }, "devDependencies": { "@types/node": "~14.17.5", - "@types/vscode": "~1.63.0", + "@types/vscode": "~1.64.0", "@typescript-eslint/eslint-plugin": "^5.10.0", "@typescript-eslint/parser": "^5.10.0", "@vscode/test-electron": "^2.1.1", @@ -25,10 +26,10 @@ "typescript": "^4.5.5", "typescript-formatter": "^7.2.2", "vsce": "^2.6.7", - "vscode-dts": "^0.3.1" + "vscode-dts": "^0.3.3" }, "engines": { - "vscode": "^1.63.0" + "vscode": "^1.64.0" } }, "node_modules/@eslint/eslintrc": { @@ -142,9 +143,9 @@ "dev": true }, "node_modules/@types/vscode": { - "version": "1.63.1", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.63.1.tgz", - "integrity": "sha512-Z+ZqjRcnGfHP86dvx/BtSwWyZPKQ/LBdmAVImY82TphyjOw2KgTKcp7Nx92oNwCTsHzlshwexAG/WiY2JuUm3g==", + "version": "1.64.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.64.0.tgz", + "integrity": "sha512-bSlAWz5WtcSL3cO9tAT/KpEH9rv5OBnm93OIIFwdCshaAiqr2bp1AUyEwW9MWeCvZBHEXc3V0fTYVdVyzDNwHA==", "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { @@ -3586,39 +3587,39 @@ } }, "node_modules/vscode-jsonrpc": { - "version": "8.0.0-next.5", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.5.tgz", - "integrity": "sha512-owRllqcFTnz5rXxcbmHPFGmpFmLqj9Z1V3Dzrv+s8ejOHLIT62Pyb5Uqzyl2/in2VP22DmzErPgZwrxjLCIKiQ==", + "version": "8.0.0-next.6", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz", + "integrity": "sha512-6Ld3RYjygn5Ih7CkAtcAwiDQC+rakj2O+PnASfNyYv3sLmm44eJpEKzuPUN30Iy2UB09AZg8T6LBKWTJTEJDVw==", "engines": { "node": ">=14.0.0" } }, "node_modules/vscode-languageclient": { - "version": "8.0.0-next.8", - "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.8.tgz", - "integrity": "sha512-CBdYRIVqqlRmZ2YBeTk0S2QMtsL8ZJfbddlfvERmRPXW4Pimr7Nk+mYq16F/k3HbrO9Xt+RAFP1t6FIIbmuUGw==", + "version": "8.0.0-next.12", + "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.12.tgz", + "integrity": "sha512-4+kr1BQcoh+sA5/4XJDJXrQXGQ5Yz/x+WpsVGGzK/TOB7RwQ63ooxG6Ej7i/+aOQM4/QdmcYWmipDtG7vqcOiw==", "dependencies": { "minimatch": "^3.0.4", "semver": "^7.3.5", - "vscode-languageserver-protocol": "3.17.0-next.12" + "vscode-languageserver-protocol": "3.17.0-next.14" }, "engines": { "vscode": "^1.63.0" } }, "node_modules/vscode-languageserver-protocol": { - "version": "3.17.0-next.12", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.12.tgz", - "integrity": "sha512-VLRcWKOpCXcx9UrqrS+NSF6pNxV498VGYGW+eyp9a79/F9ElUq3wdG6acXYlEfpWHuIxpm6MXps8FU88wqIgTg==", + "version": "3.17.0-next.14", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.14.tgz", + "integrity": "sha512-iangobY8dL6sFZkOx4OhRPJM9gN0I1caUsOVR+MnPozsqQUtwMXmbIcfaIf0Akp0pd3KhJDPf/tdwRX68QGeeA==", "dependencies": { - "vscode-jsonrpc": "8.0.0-next.5", - "vscode-languageserver-types": "3.17.0-next.6" + "vscode-jsonrpc": "8.0.0-next.6", + "vscode-languageserver-types": "3.17.0-next.7" } }, "node_modules/vscode-languageserver-types": { - "version": "3.17.0-next.6", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.6.tgz", - "integrity": "sha512-rHYeCotiabJHgvIYzWjV8g0dHCxyOQtcryTv1Xa1horaQ4jx2V+rjLBstc6zMpCyrnZcjorwEcAvGBDCd6wudw==" + "version": "3.17.0-next.7", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.7.tgz", + "integrity": "sha512-KH4zdG1qBXxoso61ChgpeoZYyHGJo8bV7Jv4I+fwQ1Ryy59JAxoZ9GAbhR5TeeafHctLcg6RFvY3m8Jqfu17cg==" }, "node_modules/which": { "version": "2.0.2", @@ -3799,9 +3800,9 @@ "dev": true }, "@types/vscode": { - "version": "1.63.1", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.63.1.tgz", - "integrity": "sha512-Z+ZqjRcnGfHP86dvx/BtSwWyZPKQ/LBdmAVImY82TphyjOw2KgTKcp7Nx92oNwCTsHzlshwexAG/WiY2JuUm3g==", + "version": "1.64.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.64.0.tgz", + "integrity": "sha512-bSlAWz5WtcSL3cO9tAT/KpEH9rv5OBnm93OIIFwdCshaAiqr2bp1AUyEwW9MWeCvZBHEXc3V0fTYVdVyzDNwHA==", "dev": true }, "@typescript-eslint/eslint-plugin": { @@ -6407,33 +6408,33 @@ } }, "vscode-jsonrpc": { - "version": "8.0.0-next.5", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.5.tgz", - "integrity": "sha512-owRllqcFTnz5rXxcbmHPFGmpFmLqj9Z1V3Dzrv+s8ejOHLIT62Pyb5Uqzyl2/in2VP22DmzErPgZwrxjLCIKiQ==" + "version": "8.0.0-next.6", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz", + "integrity": "sha512-6Ld3RYjygn5Ih7CkAtcAwiDQC+rakj2O+PnASfNyYv3sLmm44eJpEKzuPUN30Iy2UB09AZg8T6LBKWTJTEJDVw==" }, "vscode-languageclient": { - "version": "8.0.0-next.8", - "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.8.tgz", - "integrity": "sha512-CBdYRIVqqlRmZ2YBeTk0S2QMtsL8ZJfbddlfvERmRPXW4Pimr7Nk+mYq16F/k3HbrO9Xt+RAFP1t6FIIbmuUGw==", + "version": "8.0.0-next.12", + "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.12.tgz", + "integrity": "sha512-4+kr1BQcoh+sA5/4XJDJXrQXGQ5Yz/x+WpsVGGzK/TOB7RwQ63ooxG6Ej7i/+aOQM4/QdmcYWmipDtG7vqcOiw==", "requires": { "minimatch": "^3.0.4", "semver": "^7.3.5", - "vscode-languageserver-protocol": "3.17.0-next.12" + "vscode-languageserver-protocol": "3.17.0-next.14" } }, "vscode-languageserver-protocol": { - "version": "3.17.0-next.12", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.12.tgz", - "integrity": "sha512-VLRcWKOpCXcx9UrqrS+NSF6pNxV498VGYGW+eyp9a79/F9ElUq3wdG6acXYlEfpWHuIxpm6MXps8FU88wqIgTg==", + "version": "3.17.0-next.14", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.14.tgz", + "integrity": "sha512-iangobY8dL6sFZkOx4OhRPJM9gN0I1caUsOVR+MnPozsqQUtwMXmbIcfaIf0Akp0pd3KhJDPf/tdwRX68QGeeA==", "requires": { - "vscode-jsonrpc": "8.0.0-next.5", - "vscode-languageserver-types": "3.17.0-next.6" + "vscode-jsonrpc": "8.0.0-next.6", + "vscode-languageserver-types": "3.17.0-next.7" } }, "vscode-languageserver-types": { - "version": "3.17.0-next.6", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.6.tgz", - "integrity": "sha512-rHYeCotiabJHgvIYzWjV8g0dHCxyOQtcryTv1Xa1horaQ4jx2V+rjLBstc6zMpCyrnZcjorwEcAvGBDCd6wudw==" + "version": "3.17.0-next.7", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.7.tgz", + "integrity": "sha512-KH4zdG1qBXxoso61ChgpeoZYyHGJo8bV7Jv4I+fwQ1Ryy59JAxoZ9GAbhR5TeeafHctLcg6RFvY3m8Jqfu17cg==" }, "which": { "version": "2.0.2", diff --git a/editors/code/package.json b/editors/code/package.json index 3ddae8109efe..ac6492f4633b 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -21,9 +21,11 @@ "Programming Languages" ], "engines": { - "vscode": "^1.63.0" + "vscode": "^1.64.0" }, - "enableProposedApi": true, + "enabledApiProposals": [ + "inlayHints" + ], "scripts": { "vscode:prepublish": "npm run build-base -- --minify", "package": "vsce package -o rust-analyzer.vsix", @@ -33,16 +35,17 @@ "lint": "tsfmt --verify && eslint -c .eslintrc.js --ext ts ./src ./tests", "fix": " tsfmt -r && eslint -c .eslintrc.js --ext ts ./src ./tests --fix", "pretest": "tsc && npm run build", - "test": "node ./out/tests/runTests.js" + "test": "node ./out/tests/runTests.js", + "postinstall": "vscode-dts dev" }, "dependencies": { - "vscode-languageclient": "8.0.0-next.8", + "vscode-languageclient": "8.0.0-next.12", "d3": "^7.3.0", "d3-graphviz": "^4.0.0" }, "devDependencies": { "@types/node": "~14.17.5", - "@types/vscode": "~1.63.0", + "@types/vscode": "~1.64.0", "@typescript-eslint/eslint-plugin": "^5.10.0", "@typescript-eslint/parser": "^5.10.0", "@vscode/test-electron": "^2.1.1", @@ -52,7 +55,7 @@ "typescript": "^4.5.5", "typescript-formatter": "^7.2.2", "vsce": "^2.6.7", - "vscode-dts": "^0.3.1" + "vscode-dts": "^0.3.3" }, "activationEvents": [ "onLanguage:rust", diff --git a/editors/code/tsconfig.json b/editors/code/tsconfig.json index 46fd163dcb12..6bf206153a3d 100644 --- a/editors/code/tsconfig.json +++ b/editors/code/tsconfig.json @@ -23,6 +23,6 @@ "include": [ "src", "tests", - "vscode.proposed.d.ts" + "vscode.proposed.inlayHints.d.ts" ] } From 2ae8248ceec0fbf55c00c3b9e46ea319203d1df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 9 Feb 2022 19:13:17 +0200 Subject: [PATCH 03/16] Add log messages --- editors/code/src/inlay_hints.ts | 6 ++++-- editors/code/src/lsp_ext.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index af45d7032de9..b049ed44811e 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -22,8 +22,10 @@ export function activateInlayHints(ctx: Ctx) { this.hintsProvider = vscode.languages.registerInlayHintsProvider({ scheme: 'file', language: 'rust' }, new class implements vscode.InlayHintsProvider { onDidChangeInlayHints = event; async provideInlayHints(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken): Promise { + console.log(document.uri.toString()); const request = { textDocument: { uri: document.uri.toString() }, range: { start: range.start, end: range.end } }; - const hints = await sendRequestWithRetry(ctx.client, ra.inlayHints, request, token).catch(_ => null) + const hints = await sendRequestWithRetry(ctx.client, ra.inlayHints, request, token).catch(_ => null); + console.log(hints); if (hints == null) { return []; } else { @@ -43,7 +45,7 @@ export function activateInlayHints(ctx: Ctx) { this.hintsProvider = null; this.updateHintsEventEmitter.dispose(); }, - } + }; ctx.pushCleanup(maybeUpdater); diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 03cd15200ba3..bdb6a4ca1648 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -102,7 +102,7 @@ export const relatedTests = new lc.RequestType("rust-analyzer/inlayHints"); From 5a49dbd2e07c99fc0bdfb5940e064fac580d2c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 9 Feb 2022 19:14:18 +0200 Subject: [PATCH 04/16] Update inlay hints for upstream --- crates/rust-analyzer/src/lsp_ext.rs | 26 +++++++++++++++----------- crates/rust-analyzer/src/to_proto.rs | 16 ++++++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 7e7f96da21e1..1681c766f363 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -242,21 +242,25 @@ pub struct InlayHintsParams { pub text_document: TextDocumentIdentifier, } -#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] -pub enum InlayKind { - Other, - Type, - Parameter, +#[derive(Eq, PartialEq, Debug, Copy, Clone, Serialize, Deserialize)] +#[serde(transparent)] +pub struct InlayHintKind(u8); + +impl InlayHintKind { + pub const OTHER: InlayHintKind = InlayHintKind(0); + pub const TYPE: InlayHintKind = InlayHintKind(1); + pub const PARAMETER: InlayHintKind = InlayHintKind(2); } #[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct InlayHint { - pub text: String, - pub range: Range, - pub kind: Option, - pub description: Option, - pub whitespace_before: Option, - pub whitespace_after: Option, + pub label: String, + pub position: Position, + pub kind: Option, + pub tooltip: Option, + pub padding_left: Option, + pub padding_right: Option, } pub enum Ssr {} diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index a5d7b3a86f78..59b5a9173986 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -412,16 +412,16 @@ pub(crate) fn signature_help( pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ext::InlayHint { lsp_ext::InlayHint { - text: inlay_hint.label.to_string(), - range: range(line_index, inlay_hint.range), + label: inlay_hint.label.to_string(), + position: position(line_index, inlay_hint.range.start()), kind: Some(match inlay_hint.kind { - InlayKind::ParameterHint => lsp_ext::InlayKind::Parameter, - InlayKind::TypeHint => lsp_ext::InlayKind::Type, - InlayKind::ChainingHint => lsp_ext::InlayKind::Other, + InlayKind::ParameterHint => lsp_ext::InlayHintKind::PARAMETER, + InlayKind::TypeHint => lsp_ext::InlayHintKind::TYPE, + InlayKind::ChainingHint => lsp_ext::InlayHintKind::OTHER, }), - description: Some("test description".to_string()), - whitespace_before: Some(true), - whitespace_after: Some(true), + tooltip: Some("test description".to_string()), + padding_left: Some(true), + padding_right: Some(true), } } From 0b69717ab6e5d1bd57faccbe741d947da9edbff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Thu, 10 Feb 2022 12:16:02 +0200 Subject: [PATCH 05/16] Fixes --- crates/rust-analyzer/src/lsp_ext.rs | 1 - crates/rust-analyzer/src/to_proto.rs | 4 ++-- editors/code/src/inlay_hints.ts | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 1681c766f363..f57080542c17 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -247,7 +247,6 @@ pub struct InlayHintsParams { pub struct InlayHintKind(u8); impl InlayHintKind { - pub const OTHER: InlayHintKind = InlayHintKind(0); pub const TYPE: InlayHintKind = InlayHintKind(1); pub const PARAMETER: InlayHintKind = InlayHintKind(2); } diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 59b5a9173986..73c9fed59b99 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -413,11 +413,11 @@ pub(crate) fn signature_help( pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ext::InlayHint { lsp_ext::InlayHint { label: inlay_hint.label.to_string(), - position: position(line_index, inlay_hint.range.start()), + position: position(line_index, inlay_hint.range.end()), kind: Some(match inlay_hint.kind { InlayKind::ParameterHint => lsp_ext::InlayHintKind::PARAMETER, InlayKind::TypeHint => lsp_ext::InlayHintKind::TYPE, - InlayKind::ChainingHint => lsp_ext::InlayHintKind::OTHER, + InlayKind::ChainingHint => lsp_ext::InlayHintKind::TYPE, }), tooltip: Some("test description".to_string()), padding_left: Some(true), diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index b049ed44811e..ff16ef304988 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -22,13 +22,14 @@ export function activateInlayHints(ctx: Ctx) { this.hintsProvider = vscode.languages.registerInlayHintsProvider({ scheme: 'file', language: 'rust' }, new class implements vscode.InlayHintsProvider { onDidChangeInlayHints = event; async provideInlayHints(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken): Promise { - console.log(document.uri.toString()); const request = { textDocument: { uri: document.uri.toString() }, range: { start: range.start, end: range.end } }; const hints = await sendRequestWithRetry(ctx.client, ra.inlayHints, request, token).catch(_ => null); - console.log(hints); if (hints == null) { return []; } else { + for (let hint of hints) { + hint.position = new vscode.Position(hint.position.line, hint.position.character); + } return hints; } } From 9c0c199e962ef90fe3bf152bc87ff96d5c2a9093 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 12 Feb 2022 01:03:32 +0200 Subject: [PATCH 06/16] Clean up the redundant hints code and config --- crates/rust-analyzer/src/to_proto.rs | 10 ++-- editors/code/package.json | 87 +--------------------------- editors/code/tsconfig.json | 3 +- 3 files changed, 9 insertions(+), 91 deletions(-) diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 73c9fed59b99..8e6e4099adf4 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -414,11 +414,11 @@ pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_e lsp_ext::InlayHint { label: inlay_hint.label.to_string(), position: position(line_index, inlay_hint.range.end()), - kind: Some(match inlay_hint.kind { - InlayKind::ParameterHint => lsp_ext::InlayHintKind::PARAMETER, - InlayKind::TypeHint => lsp_ext::InlayHintKind::TYPE, - InlayKind::ChainingHint => lsp_ext::InlayHintKind::TYPE, - }), + kind: match inlay_hint.kind { + InlayKind::ParameterHint => Some(lsp_ext::InlayHintKind::PARAMETER), + InlayKind::TypeHint => Some(lsp_ext::InlayHintKind::TYPE), + InlayKind::ChainingHint => None, + }, tooltip: Some("test description".to_string()), padding_left: Some(true), padding_right: Some(true), diff --git a/editors/code/package.json b/editors/code/package.json index ac6492f4633b..19a62f65144e 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -23,9 +23,7 @@ "engines": { "vscode": "^1.64.0" }, - "enabledApiProposals": [ - "inlayHints" - ], + "enabledApiProposals": [], "scripts": { "vscode:prepublish": "npm run build-base -- --minify", "package": "vsce package -o rust-analyzer.vsix", @@ -35,8 +33,7 @@ "lint": "tsfmt --verify && eslint -c .eslintrc.js --ext ts ./src ./tests", "fix": " tsfmt -r && eslint -c .eslintrc.js --ext ts ./src ./tests --fix", "pretest": "tsc && npm run build", - "test": "node ./out/tests/runTests.js", - "postinstall": "vscode-dts dev" + "test": "node ./out/tests/runTests.js" }, "dependencies": { "vscode-languageclient": "8.0.0-next.12", @@ -54,8 +51,7 @@ "tslib": "^2.3.0", "typescript": "^4.5.5", "typescript-formatter": "^7.2.2", - "vsce": "^2.6.7", - "vscode-dts": "^0.3.3" + "vsce": "^2.6.7" }, "activationEvents": [ "onLanguage:rust", @@ -302,11 +298,6 @@ "default": true, "description": "Whether to show inlay hints." }, - "rust-analyzer.inlayHints.smallerHints": { - "type": "boolean", - "default": true, - "description": "Whether inlay hints font size should be smaller than editor's font size." - }, "rust-analyzer.server.path": { "type": [ "null", @@ -1087,78 +1078,6 @@ } ], "colors": [ - { - "id": "rust_analyzer.inlayHints.foreground", - "description": "Foreground color of inlay hints (is overriden by more specific rust_analyzer.inlayHints.foreground.* configurations)", - "defaults": { - "dark": "#A0A0A0F0", - "light": "#747474", - "highContrast": "#BEBEBE" - } - }, - { - "id": "rust_analyzer.inlayHints.background", - "description": "Background color of inlay hints (is overriden by more specific rust_analyzer.inlayHints.background.* configurations)", - "defaults": { - "dark": "#11223300", - "light": "#11223300", - "highContrast": "#11223300" - } - }, - { - "id": "rust_analyzer.inlayHints.foreground.typeHints", - "description": "Foreground color of inlay type hints for variables (overrides rust_analyzer.inlayHints.foreground)", - "defaults": { - "dark": "rust_analyzer.inlayHints.foreground", - "light": "rust_analyzer.inlayHints.foreground", - "highContrast": "rust_analyzer.inlayHints.foreground" - } - }, - { - "id": "rust_analyzer.inlayHints.foreground.chainingHints", - "description": "Foreground color of inlay type hints for method chains (overrides rust_analyzer.inlayHints.foreground)", - "defaults": { - "dark": "rust_analyzer.inlayHints.foreground", - "light": "rust_analyzer.inlayHints.foreground", - "highContrast": "rust_analyzer.inlayHints.foreground" - } - }, - { - "id": "rust_analyzer.inlayHints.foreground.parameterHints", - "description": "Foreground color of function parameter name inlay hints at the call site (overrides rust_analyzer.inlayHints.foreground)", - "defaults": { - "dark": "rust_analyzer.inlayHints.foreground", - "light": "rust_analyzer.inlayHints.foreground", - "highContrast": "rust_analyzer.inlayHints.foreground" - } - }, - { - "id": "rust_analyzer.inlayHints.background.typeHints", - "description": "Background color of inlay type hints for variables (overrides rust_analyzer.inlayHints.background)", - "defaults": { - "dark": "rust_analyzer.inlayHints.background", - "light": "rust_analyzer.inlayHints.background", - "highContrast": "rust_analyzer.inlayHints.background" - } - }, - { - "id": "rust_analyzer.inlayHints.background.chainingHints", - "description": "Background color of inlay type hints for method chains (overrides rust_analyzer.inlayHints.background)", - "defaults": { - "dark": "rust_analyzer.inlayHints.background", - "light": "rust_analyzer.inlayHints.background", - "highContrast": "rust_analyzer.inlayHints.background" - } - }, - { - "id": "rust_analyzer.inlayHints.background.parameterHints", - "description": "Background color of function parameter name inlay hints at the call site (overrides rust_analyzer.inlayHints.background)", - "defaults": { - "dark": "rust_analyzer.inlayHints.background", - "light": "rust_analyzer.inlayHints.background", - "highContrast": "rust_analyzer.inlayHints.background" - } - }, { "id": "rust_analyzer.syntaxTreeBorder", "description": "Color of the border displayed in the Rust source code for the selected syntax node (see \"Show Syntax Tree\" command)", diff --git a/editors/code/tsconfig.json b/editors/code/tsconfig.json index 6bf206153a3d..7c4fbd21ebec 100644 --- a/editors/code/tsconfig.json +++ b/editors/code/tsconfig.json @@ -22,7 +22,6 @@ ], "include": [ "src", - "tests", - "vscode.proposed.inlayHints.d.ts" + "tests" ] } From b1d8dae930deb73a0d11c310f11785e4c1fbb3c9 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 12 Feb 2022 00:48:01 +0200 Subject: [PATCH 07/16] Load hints for part of the file only --- crates/ide/src/inlay_hints.rs | 113 ++++++++++++++++++++++----- crates/ide/src/lib.rs | 3 +- crates/ide/src/static_index.rs | 1 + crates/rust-analyzer/src/handlers.rs | 11 ++- crates/rust-analyzer/src/lsp_ext.rs | 1 + 5 files changed, 108 insertions(+), 21 deletions(-) diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 2ca756cbe044..3dc72731cb9e 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -5,7 +5,7 @@ use itertools::Itertools; use stdx::to_lower_snake_case; use syntax::{ ast::{self, AstNode, HasArgList, HasName, UnaryOp}, - match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, + match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, SyntaxNode, TextRange, T, }; use crate::FileId; @@ -58,6 +58,7 @@ pub struct InlayHint { pub(crate) fn inlay_hints( db: &RootDatabase, file_id: FileId, + range_limit: Option, config: &InlayHintsConfig, ) -> Vec { let _p = profile::span("inlay_hints"); @@ -65,25 +66,50 @@ pub(crate) fn inlay_hints( let file = sema.parse(file_id); let file = file.syntax(); - let mut res = Vec::new(); - - for node in file.descendants() { - if let Some(expr) = ast::Expr::cast(node.clone()) { - get_chaining_hints(&mut res, &sema, config, &expr); - match expr { - ast::Expr::CallExpr(it) => { - get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); - } - ast::Expr::MethodCallExpr(it) => { - get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); + let mut hints = Vec::new(); + + if let Some(range_limit) = range_limit { + let range_limit = range_limit.range; + match file.covering_element(range_limit) { + NodeOrToken::Token(_) => return hints, + NodeOrToken::Node(n) => { + for node in n + .descendants() + .filter(|descendant| range_limit.contains_range(descendant.text_range())) + { + get_hints(&mut hints, &sema, config, node); } - _ => (), } - } else if let Some(it) = ast::IdentPat::cast(node.clone()) { - get_bind_pat_hints(&mut res, &sema, config, &it); } + } else { + for node in file.descendants() { + get_hints(&mut hints, &sema, config, node); + } + } + + hints +} + +fn get_hints( + hints: &mut Vec, + sema: &Semantics, + config: &InlayHintsConfig, + node: SyntaxNode, +) { + if let Some(expr) = ast::Expr::cast(node.clone()) { + get_chaining_hints(hints, sema, config, &expr); + match expr { + ast::Expr::CallExpr(it) => { + get_param_name_hints(hints, sema, config, ast::Expr::from(it)); + } + ast::Expr::MethodCallExpr(it) => { + get_param_name_hints(hints, sema, config, ast::Expr::from(it)); + } + _ => (), + } + } else if let Some(it) = ast::IdentPat::cast(node) { + get_bind_pat_hints(hints, sema, config, &it); } - res } fn get_chaining_hints( @@ -541,6 +567,8 @@ fn get_callable( #[cfg(test)] mod tests { use expect_test::{expect, Expect}; + use ide_db::base_db::FileRange; + use syntax::{TextRange, TextSize}; use test_utils::extract_annotations; use crate::{fixture, inlay_hints::InlayHintsConfig}; @@ -604,7 +632,7 @@ mod tests { fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { let (analysis, file_id) = fixture::file(ra_fixture); let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); - let inlay_hints = analysis.inlay_hints(&config, file_id).unwrap(); + let inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap(); let actual = inlay_hints.into_iter().map(|it| (it.range, it.label.to_string())).collect::>(); assert_eq!(expected, actual, "\nExpected:\n{:#?}\n\nActual:\n{:#?}", expected, actual); @@ -613,7 +641,7 @@ mod tests { #[track_caller] fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) { let (analysis, file_id) = fixture::file(ra_fixture); - let inlay_hints = analysis.inlay_hints(&config, file_id).unwrap(); + let inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap(); expect.assert_debug_eq(&inlay_hints) } @@ -1045,6 +1073,55 @@ fn main() { ) } + #[test] + fn check_hint_range_limit() { + let fixture = r#" + //- minicore: fn, sized + fn foo() -> impl Fn() { loop {} } + fn foo1() -> impl Fn(f64) { loop {} } + fn foo2() -> impl Fn(f64, f64) { loop {} } + fn foo3() -> impl Fn(f64, f64) -> u32 { loop {} } + fn foo4() -> &'static dyn Fn(f64, f64) -> u32 { loop {} } + fn foo5() -> &'static dyn Fn(&'static dyn Fn(f64, f64) -> u32, f64) -> u32 { loop {} } + fn foo6() -> impl Fn(f64, f64) -> u32 + Sized { loop {} } + fn foo7() -> *const (impl Fn(f64, f64) -> u32 + Sized) { loop {} } + + fn main() { + let foo = foo(); + let foo = foo1(); + let foo = foo2(); + let foo = foo3(); + // ^^^ impl Fn(f64, f64) -> u32 + let foo = foo4(); + // ^^^ &dyn Fn(f64, f64) -> u32 + let foo = foo5(); + let foo = foo6(); + let foo = foo7(); + } + "#; + let (analysis, file_id) = fixture::file(fixture); + let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); + let inlay_hints = analysis + .inlay_hints( + &InlayHintsConfig { + parameter_hints: false, + type_hints: true, + chaining_hints: false, + hide_named_constructor_hints: false, + max_length: None, + }, + file_id, + Some(FileRange { + file_id, + range: TextRange::new(TextSize::from(500), TextSize::from(600)), + }), + ) + .unwrap(); + let actual = + inlay_hints.into_iter().map(|it| (it.range, it.label.to_string())).collect::>(); + assert_eq!(expected, actual, "\nExpected:\n{:#?}\n\nActual:\n{:#?}", expected, actual); + } + #[test] fn fn_hints_ptr_rpit_fn_parentheses() { check_types( diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 4028b0bc7257..1acaaaccf0da 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -358,8 +358,9 @@ impl Analysis { &self, config: &InlayHintsConfig, file_id: FileId, + range: Option, ) -> Cancellable> { - self.with_db(|db| inlay_hints::inlay_hints(db, file_id, config)) + self.with_db(|db| inlay_hints::inlay_hints(db, file_id, range, config)) } /// Returns the set of folding ranges. diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs index d5bfbd18941c..64f2bc442332 100644 --- a/crates/ide/src/static_index.rs +++ b/crates/ide/src/static_index.rs @@ -112,6 +112,7 @@ impl StaticIndex<'_> { max_length: Some(25), }, file_id, + None, ) .unwrap(); // hovers diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index b45fbe698c99..70ffec7ed27f 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1318,11 +1318,18 @@ pub(crate) fn handle_inlay_hints( params: InlayHintsParams, ) -> Result> { let _p = profile::span("handle_inlay_hints"); - let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; + let document_uri = ¶ms.text_document.uri; + let file_id = from_proto::file_id(&snap, document_uri)?; let line_index = snap.file_line_index(file_id)?; + let range = params + .range + .map(|range| { + from_proto::file_range(&snap, TextDocumentIdentifier::new(document_uri.to_owned()), range) + }) + .transpose()?; Ok(snap .analysis - .inlay_hints(&snap.config.inlay_hints(), file_id)? + .inlay_hints(&snap.config.inlay_hints(), file_id, range)? .into_iter() .map(|it| to_proto::inlay_hint(&line_index, it)) .collect()) diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index f57080542c17..973769a7207b 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -240,6 +240,7 @@ impl Request for InlayHints { #[serde(rename_all = "camelCase")] pub struct InlayHintsParams { pub text_document: TextDocumentIdentifier, + pub range: Option, } #[derive(Eq, PartialEq, Debug, Copy, Clone, Serialize, Deserialize)] From 5de5e450cb4b0cc297a2f8499946f20a0dcf20fe Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 12 Feb 2022 08:33:04 +0200 Subject: [PATCH 08/16] Remove debugging leftovers --- crates/rust-analyzer/src/to_proto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 8e6e4099adf4..a12b3dc5ed61 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -419,7 +419,7 @@ pub(crate) fn inlay_hint(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_e InlayKind::TypeHint => Some(lsp_ext::InlayHintKind::TYPE), InlayKind::ChainingHint => None, }, - tooltip: Some("test description".to_string()), + tooltip: None, padding_left: Some(true), padding_right: Some(true), } From 8454358ba4a86d1dc6a4ab40cb60f637c1bee712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Fri, 4 Mar 2022 07:48:39 +0200 Subject: [PATCH 09/16] Bump vscode --- editors/code/package-lock.json | 95 ++++------------------------------ editors/code/package.json | 4 +- 2 files changed, 11 insertions(+), 88 deletions(-) diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 0d6e3c55cd2a..b903d21077fd 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "rust-analyzer", "version": "0.4.0-dev", - "hasInstallScript": true, "license": "MIT OR Apache-2.0", "dependencies": { "d3": "^7.3.0", @@ -16,7 +15,7 @@ }, "devDependencies": { "@types/node": "~14.17.5", - "@types/vscode": "~1.64.0", + "@types/vscode": "~1.65.0", "@typescript-eslint/eslint-plugin": "^5.10.0", "@typescript-eslint/parser": "^5.10.0", "@vscode/test-electron": "^2.1.1", @@ -25,11 +24,10 @@ "tslib": "^2.3.0", "typescript": "^4.5.5", "typescript-formatter": "^7.2.2", - "vsce": "^2.6.7", - "vscode-dts": "^0.3.3" + "vsce": "^2.6.7" }, "engines": { - "vscode": "^1.64.0" + "vscode": "^1.65.0" } }, "node_modules/@eslint/eslintrc": { @@ -143,9 +141,9 @@ "dev": true }, "node_modules/@types/vscode": { - "version": "1.64.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.64.0.tgz", - "integrity": "sha512-bSlAWz5WtcSL3cO9tAT/KpEH9rv5OBnm93OIIFwdCshaAiqr2bp1AUyEwW9MWeCvZBHEXc3V0fTYVdVyzDNwHA==", + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz", + "integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==", "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { @@ -2345,15 +2343,6 @@ "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": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -2777,19 +2766,6 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "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": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -3101,12 +3077,6 @@ "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": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -3572,20 +3542,6 @@ "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": { "version": "8.0.0-next.6", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz", @@ -3800,9 +3756,9 @@ "dev": true }, "@types/vscode": { - "version": "1.64.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.64.0.tgz", - "integrity": "sha512-bSlAWz5WtcSL3cO9tAT/KpEH9rv5OBnm93OIIFwdCshaAiqr2bp1AUyEwW9MWeCvZBHEXc3V0fTYVdVyzDNwHA==", + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz", + "integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==", "dev": true }, "@typescript-eslint/eslint-plugin": { @@ -5443,12 +5399,6 @@ "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": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -5791,16 +5741,6 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "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": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -6020,12 +5960,6 @@ "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": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -6396,17 +6330,6 @@ } } }, - "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": { "version": "8.0.0-next.6", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz", diff --git a/editors/code/package.json b/editors/code/package.json index 19a62f65144e..4fd570220fde 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -21,7 +21,7 @@ "Programming Languages" ], "engines": { - "vscode": "^1.64.0" + "vscode": "^1.65.0" }, "enabledApiProposals": [], "scripts": { @@ -42,7 +42,7 @@ }, "devDependencies": { "@types/node": "~14.17.5", - "@types/vscode": "~1.64.0", + "@types/vscode": "~1.65.0", "@typescript-eslint/eslint-plugin": "^5.10.0", "@typescript-eslint/parser": "^5.10.0", "@vscode/test-electron": "^2.1.1", From 9d432915330e5b67fc39de673d954966dffce7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Fri, 4 Mar 2022 08:08:14 +0200 Subject: [PATCH 10/16] Drop hint conversion --- editors/code/src/inlay_hints.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index ff16ef304988..441370a677ab 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -27,9 +27,6 @@ export function activateInlayHints(ctx: Ctx) { if (hints == null) { return []; } else { - for (let hint of hints) { - hint.position = new vscode.Position(hint.position.line, hint.position.character); - } return hints; } } From 4b16b9b74bcc17eeeda8baf78b6ce11c2fd43e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Fri, 4 Mar 2022 08:15:17 +0200 Subject: [PATCH 11/16] Fix formatting --- crates/rust-analyzer/src/handlers.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 70ffec7ed27f..249e861f9b72 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1324,7 +1324,11 @@ pub(crate) fn handle_inlay_hints( let range = params .range .map(|range| { - from_proto::file_range(&snap, TextDocumentIdentifier::new(document_uri.to_owned()), range) + from_proto::file_range( + &snap, + TextDocumentIdentifier::new(document_uri.to_owned()), + range, + ) }) .transpose()?; Ok(snap From b9d74fe2ed578f0b48f7773cde432df80531bb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Fri, 4 Mar 2022 08:26:44 +0200 Subject: [PATCH 12/16] Update LSP docs --- crates/rust-analyzer/src/lsp_ext.rs | 2 +- docs/dev/lsp-extensions.md | 15 +++++++++------ editors/code/src/lsp_ext.ts | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 973769a7207b..846f15130442 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -233,7 +233,7 @@ pub enum InlayHints {} impl Request for InlayHints { type Params = InlayHintsParams; type Result = Vec; - const METHOD: &'static str = "rust-analyzer/inlayHints"; + const METHOD: &'static str = "experimental/inlayHints"; } #[derive(Serialize, Deserialize, Debug)] diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index 85df1188a8a7..9f1c7fe0a3a6 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -1,5 +1,5 @@