diff options
author | Emil Lauridsen <[email protected]> | 2019-11-18 17:02:28 +0000 |
---|---|---|
committer | Emil Lauridsen <[email protected]> | 2019-11-19 16:23:50 +0000 |
commit | dadad36bb9770f9b13ed84bc219ea0168a7a5bf1 (patch) | |
tree | 00051540da204b4294501f3c56960975177ae502 /crates/ra_hir/src/ty.rs | |
parent | c24ee0990486b04723534f072d7a58e829bbd1bd (diff) |
Move type inlay hint truncation to language server
This commit implements a general truncation framework for HirFormatter
that keeps track of how much has been output so far. This information
can then be used to perform truncation inside the language server,
instead of relying on the client.
Initial support is implemented for truncating types hints using the
maxInlayHintLength server config option. The existing solution in the
VSCode extension has been removed in favor of letting the server
truncate type hints.
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index b7f50b714..776613c7c 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -800,6 +800,10 @@ impl HirDisplay for &Ty { | |||
800 | 800 | ||
801 | impl HirDisplay for ApplicationTy { | 801 | impl HirDisplay for ApplicationTy { |
802 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 802 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
803 | if f.should_truncate() { | ||
804 | return write!(f, "…"); | ||
805 | } | ||
806 | |||
803 | match self.ctor { | 807 | match self.ctor { |
804 | TypeCtor::Bool => write!(f, "bool")?, | 808 | TypeCtor::Bool => write!(f, "bool")?, |
805 | TypeCtor::Char => write!(f, "char")?, | 809 | TypeCtor::Char => write!(f, "char")?, |
@@ -901,6 +905,10 @@ impl HirDisplay for ApplicationTy { | |||
901 | 905 | ||
902 | impl HirDisplay for ProjectionTy { | 906 | impl HirDisplay for ProjectionTy { |
903 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 907 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
908 | if f.should_truncate() { | ||
909 | return write!(f, "…"); | ||
910 | } | ||
911 | |||
904 | let trait_name = self | 912 | let trait_name = self |
905 | .associated_ty | 913 | .associated_ty |
906 | .parent_trait(f.db) | 914 | .parent_trait(f.db) |
@@ -919,6 +927,10 @@ impl HirDisplay for ProjectionTy { | |||
919 | 927 | ||
920 | impl HirDisplay for Ty { | 928 | impl HirDisplay for Ty { |
921 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 929 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
930 | if f.should_truncate() { | ||
931 | return write!(f, "…"); | ||
932 | } | ||
933 | |||
922 | match self { | 934 | match self { |
923 | Ty::Apply(a_ty) => a_ty.hir_fmt(f)?, | 935 | Ty::Apply(a_ty) => a_ty.hir_fmt(f)?, |
924 | Ty::Projection(p_ty) => p_ty.hir_fmt(f)?, | 936 | Ty::Projection(p_ty) => p_ty.hir_fmt(f)?, |
@@ -1001,6 +1013,10 @@ impl HirDisplay for Ty { | |||
1001 | 1013 | ||
1002 | impl TraitRef { | 1014 | impl TraitRef { |
1003 | fn hir_fmt_ext(&self, f: &mut HirFormatter<impl HirDatabase>, use_as: bool) -> fmt::Result { | 1015 | fn hir_fmt_ext(&self, f: &mut HirFormatter<impl HirDatabase>, use_as: bool) -> fmt::Result { |
1016 | if f.should_truncate() { | ||
1017 | return write!(f, "…"); | ||
1018 | } | ||
1019 | |||
1004 | self.substs[0].hir_fmt(f)?; | 1020 | self.substs[0].hir_fmt(f)?; |
1005 | if use_as { | 1021 | if use_as { |
1006 | write!(f, " as ")?; | 1022 | write!(f, " as ")?; |
@@ -1031,6 +1047,10 @@ impl HirDisplay for &GenericPredicate { | |||
1031 | 1047 | ||
1032 | impl HirDisplay for GenericPredicate { | 1048 | impl HirDisplay for GenericPredicate { |
1033 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 1049 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
1050 | if f.should_truncate() { | ||
1051 | return write!(f, "…"); | ||
1052 | } | ||
1053 | |||
1034 | match self { | 1054 | match self { |
1035 | GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, | 1055 | GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, |
1036 | GenericPredicate::Projection(projection_pred) => { | 1056 | GenericPredicate::Projection(projection_pred) => { |