|
| 1 | +use std::{collections::HashMap, sync::LazyLock}; |
| 2 | + |
1 | 3 | use async_lsp::lsp_types::MarkedString;
|
2 | 4 |
|
3 | 5 | use crate::{
|
4 | 6 | formatter::ProtoFormatter, state::ProtoLanguageState, utils::split_identifier_package,
|
5 | 7 | };
|
6 | 8 |
|
| 9 | + |
| 10 | +static BUITIN_DOCS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| { |
| 11 | + HashMap::from([ |
| 12 | + ( |
| 13 | + "int32", |
| 14 | + r#"A 32-bit integer (varint encoding) |
| 15 | +
|
| 16 | +Values of this type range between `-2147483648` and `2147483647`. |
| 17 | +Beware that negative values are encoded as five bytes on the wire!"#, |
| 18 | + ), |
| 19 | + ( |
| 20 | + "int64", |
| 21 | + r#"A 64-bit integer (varint encoding) |
| 22 | +
|
| 23 | +Values of this type range between `-9223372036854775808` and `9223372036854775807`. |
| 24 | +Beware that negative values are encoded as ten bytes on the wire!"#, |
| 25 | + ), |
| 26 | + ( |
| 27 | + "uint32", |
| 28 | + r#"A 32-bit unsigned integer (varint encoding) |
| 29 | +
|
| 30 | +Values of this type range between `0` and `4294967295`."#, |
| 31 | + ), |
| 32 | + ( |
| 33 | + "uint64", |
| 34 | + r#"A 64-bit unsigned integer (varint encoding) |
| 35 | +
|
| 36 | +Values of this type range between `0` and `18446744073709551615`."#, |
| 37 | + ), |
| 38 | + ( |
| 39 | + "sint32", |
| 40 | + r#"A 32-bit integer (ZigZag encoding) |
| 41 | +
|
| 42 | +Values of this type range between `-2147483648` and `2147483647`."#, |
| 43 | + ), |
| 44 | + ( |
| 45 | + "sint64", |
| 46 | + r#"A 64-bit integer (ZigZag encoding) |
| 47 | +
|
| 48 | +Values of this type range between `-9223372036854775808` and `9223372036854775807`."#, |
| 49 | + ), |
| 50 | + ( |
| 51 | + "fixed32", |
| 52 | + r#"A 32-bit unsigned integer (4-byte encoding) |
| 53 | +
|
| 54 | +Values of this type range between `0` and `4294967295`."#, |
| 55 | + ), |
| 56 | + ( |
| 57 | + "fixed64", |
| 58 | + r#"A 64-bit unsigned integer (8-byte encoding) |
| 59 | +
|
| 60 | +Values of this type range between `0` and `18446744073709551615`."#, |
| 61 | + ), |
| 62 | + ( |
| 63 | + "sfixed32", |
| 64 | + r#"A 32-bit integer (4-byte encoding) |
| 65 | +
|
| 66 | +Values of this type range between `-2147483648` and `2147483647`."#, |
| 67 | + ), |
| 68 | + ( |
| 69 | + "sfixed64", |
| 70 | + r#"A 64-bit integer (8-byte encoding) |
| 71 | +
|
| 72 | +Values of this type range between `-9223372036854775808` and `9223372036854775807`."#, |
| 73 | + ), |
| 74 | + ( |
| 75 | + "float", |
| 76 | + "A single-precision floating point number (IEEE-745.2008 binary32).", |
| 77 | + ), |
| 78 | + ( |
| 79 | + "double", |
| 80 | + "A double-precision floating point number (IEEE-745.2008 binary64).", |
| 81 | + ), |
| 82 | + ( |
| 83 | + "string", |
| 84 | + r#"A string of text. |
| 85 | +
|
| 86 | +Stores at most 4GB of text. Intended to be UTF-8 encoded Unicode; use `bytes` if you need other encodings."#, |
| 87 | + ), |
| 88 | + ( |
| 89 | + "bytes", |
| 90 | + r#"A blob of arbitrary bytes. |
| 91 | +
|
| 92 | +Stores at most 4GB of binary data. Encoded as base64 in JSON."#, |
| 93 | + ), |
| 94 | + ( |
| 95 | + "bool", |
| 96 | + r#"A Boolean value: `true` or `false`. |
| 97 | +
|
| 98 | +Encoded as a single byte: `0x00` or `0xff` (all non-zero bytes decode to `true`)."#, |
| 99 | + ), |
| 100 | + ( |
| 101 | + "default", |
| 102 | + r#"A magic option that specifies the field's default value. |
| 103 | +
|
| 104 | +Unlike every other option on a field, this does not have a corresponding field in |
| 105 | +`google.protobuf.FieldOptions`; it is implemented by compiler magic."#, |
| 106 | + ), |
| 107 | + ]) |
| 108 | +}); |
| 109 | + |
7 | 110 | impl<F: ProtoFormatter> ProtoLanguageState<F> {
|
8 | 111 | pub fn hover(&self, curr_package: &str, identifier: &str) -> Vec<MarkedString> {
|
| 112 | + if let Some(docs) = BUITIN_DOCS.get(identifier) { |
| 113 | + return vec![MarkedString::String(docs.to_string())]; |
| 114 | + } |
| 115 | + |
9 | 116 | let (mut package, identifier) = split_identifier_package(identifier);
|
10 | 117 | if package.is_empty() {
|
11 | 118 | package = curr_package;
|
@@ -42,6 +149,7 @@ mod test {
|
42 | 149 | state.upsert_file(&c_uri, c.to_owned());
|
43 | 150 |
|
44 | 151 | assert_yaml_snapshot!(state.hover("com.workspace", "Author"));
|
| 152 | + assert_yaml_snapshot!(state.hover("com.workspace", "int64")); |
45 | 153 | assert_yaml_snapshot!(state.hover("com.workspace", "Author.Address"));
|
46 | 154 | assert_yaml_snapshot!(state.hover("com.workspace", "com.utility.Foobar.Baz"));
|
47 | 155 | assert_yaml_snapshot!(state.hover("com.utility", "Baz"));
|
|
0 commit comments