Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/rust-analyzer/src/lsp_ext.rs | 13 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 15 | ||||
| -rw-r--r-- | editors/code/.gitignore | 2 | ||||
| -rw-r--r-- | editors/code/package-lock.json | 418 | ||||
| -rw-r--r-- | editors/code/package.json | 3 | ||||
| -rw-r--r-- | editors/code/src/client.ts | 3 | ||||
| -rw-r--r-- | editors/code/src/inlay_hints.ts | 279 | ||||
| -rw-r--r-- | editors/code/src/lsp_ext.ts | 18 | ||||
| -rw-r--r-- | 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 ea98d09935..7e7f96da21 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<InlayKind>, + pub description: Option<String>, + pub whitespace_before: Option<bool>, + pub whitespace_after: Option<bool>, } pub enum Ssr {} diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index f0de166d8b..a5d7b3a86f 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 3acb6b3f62..2c975a947e 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 1f0c97ad27..313da64430 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 1252752a9a..3ddae8109e 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 26567c6df3..4e5d7bf8e8 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 c23d6f7384..af45d7032d 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<void>(), + 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<vscode.InlayHint[]> { + 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<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) { - 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<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; -} diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 9248bd1b6f..03cd15200b 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<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 { textDocument: lc.TextDocumentIdentifier; + range: lc.Range, } export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void>("rust-analyzer/inlayHints"); diff --git a/editors/code/tsconfig.json b/editors/code/tsconfig.json index 7c4fbd21eb..46fd163dcb 100644 --- a/editors/code/tsconfig.json +++ b/editors/code/tsconfig.json @@ -22,6 +22,7 @@ ], "include": [ "src", - "tests" + "tests", + "vscode.proposed.d.ts" ] } |