@@ -334,16 +334,17 @@ impl SolangServer {
334
334
let files = self . files . lock ( ) . await ;
335
335
if let Some ( cache) = files. caches . get ( & path) {
336
336
let f = & cache. file ;
337
- let offset = f. get_offset (
337
+ if let Some ( offset) = f. get_offset (
338
338
params. text_document_position_params . position . line as _ ,
339
339
params. text_document_position_params . position . character as _ ,
340
- ) ;
341
- if let Some ( reference) = cache
342
- . references
343
- . find ( offset, offset + 1 )
344
- . min_by ( |a, b| ( a. stop - a. start ) . cmp ( & ( b. stop - b. start ) ) )
345
- {
346
- return Ok ( Some ( reference. val . clone ( ) ) ) ;
340
+ ) {
341
+ if let Some ( reference) = cache
342
+ . references
343
+ . find ( offset, offset + 1 )
344
+ . min_by ( |a, b| ( a. stop - a. start ) . cmp ( & ( b. stop - b. start ) ) )
345
+ {
346
+ return Ok ( Some ( reference. val . clone ( ) ) ) ;
347
+ }
347
348
}
348
349
}
349
350
Ok ( None )
@@ -905,7 +906,7 @@ impl<'a> Builder<'a> {
905
906
}
906
907
ast:: Expression :: ConstantVariable { loc, ty, contract_no, var_no } => {
907
908
let ( contract, name) = if let Some ( contract_no) = contract_no {
908
- let contract = format ! ( "{}." , self . ns. contracts[ * contract_no] . name ) ;
909
+ let contract = format ! ( "{}." , self . ns. contracts[ * contract_no] . id ) ;
909
910
let name = & self . ns . contracts [ * contract_no] . variables [ * var_no] . name ;
910
911
( contract, name)
911
912
} else {
@@ -944,7 +945,7 @@ impl<'a> Builder<'a> {
944
945
ast:: Expression :: StorageVariable { loc, ty, contract_no, var_no } => {
945
946
let contract = & self . ns . contracts [ * contract_no] ;
946
947
let name = & contract. variables [ * var_no] . name ;
947
- let val = format ! ( "{} {}.{}" , ty. to_string( self . ns) , contract. name , name) ;
948
+ let val = format ! ( "{} {}.{}" , ty. to_string( self . ns) , contract. id , name) ;
948
949
self . hovers . push ( (
949
950
loc. file_no ( ) ,
950
951
HoverEntry {
@@ -1082,7 +1083,7 @@ impl<'a> Builder<'a> {
1082
1083
msg
1083
1084
} ) . join ( ", " ) ;
1084
1085
1085
- let contract = fnc. contract_no . map ( |contract_no| format ! ( "{}." , self . ns. contracts[ contract_no] . name ) ) . unwrap_or_default ( ) ;
1086
+ let contract = fnc. contract_no . map ( |contract_no| format ! ( "{}." , self . ns. contracts[ contract_no] . id ) ) . unwrap_or_default ( ) ;
1086
1087
1087
1088
let val = format ! ( "{} {}{}({}) returns ({})\n " , fnc. ty, contract, fnc. name, params, rets) ;
1088
1089
@@ -1140,7 +1141,7 @@ impl<'a> Builder<'a> {
1140
1141
msg
1141
1142
} ) . join ( ", " ) ;
1142
1143
1143
- let contract = fnc. contract_no . map ( |contract_no| format ! ( "{}." , self . ns. contracts[ contract_no] . name ) ) . unwrap_or_default ( ) ;
1144
+ let contract = fnc. contract_no . map ( |contract_no| format ! ( "{}." , self . ns. contracts[ contract_no] . id ) ) . unwrap_or_default ( ) ;
1144
1145
1145
1146
let val = format ! ( "{} {}{}({}) returns ({})\n " , fnc. ty, contract, fnc. name, params, rets) ;
1146
1147
@@ -1562,7 +1563,7 @@ impl<'a> Builder<'a> {
1562
1563
stop : base. loc . exclusive_end ( ) ,
1563
1564
val : make_code_block ( format ! (
1564
1565
"contract {}" ,
1565
- self . ns. contracts[ base. contract_no] . name
1566
+ self . ns. contracts[ base. contract_no] . id
1566
1567
) ) ,
1567
1568
} ,
1568
1569
) ) ;
@@ -1589,8 +1590,8 @@ impl<'a> Builder<'a> {
1589
1590
self . hovers . push ( (
1590
1591
file_no,
1591
1592
HoverEntry {
1592
- start : contract. loc . start ( ) ,
1593
- stop : contract. loc . start ( ) + contract . name . len ( ) ,
1593
+ start : contract. id . loc . start ( ) ,
1594
+ stop : contract. id . loc . exclusive_end ( ) ,
1594
1595
val : render ( & contract. tags [ ..] ) ,
1595
1596
} ,
1596
1597
) ) ;
@@ -1601,7 +1602,7 @@ impl<'a> Builder<'a> {
1601
1602
} ;
1602
1603
1603
1604
self . definitions
1604
- . insert ( cdi. clone ( ) , loc_to_range ( & contract. loc , file) ) ;
1605
+ . insert ( cdi. clone ( ) , loc_to_range ( & contract. id . loc , file) ) ;
1605
1606
1606
1607
let impls = contract
1607
1608
. functions
@@ -1719,7 +1720,9 @@ impl<'a> Builder<'a> {
1719
1720
. collect :: < HashMap < PathBuf , usize > > ( ) ;
1720
1721
1721
1722
for val in self . types . values_mut ( ) {
1722
- val. def_path = defs_to_files[ & val. def_type ] . clone ( ) ;
1723
+ if let Some ( path) = defs_to_files. get ( & val. def_type ) {
1724
+ val. def_path = path. clone ( ) ;
1725
+ }
1723
1726
}
1724
1727
1725
1728
for ( di, range) in & self . definitions {
@@ -1729,10 +1732,13 @@ impl<'a> Builder<'a> {
1729
1732
file_no,
1730
1733
ReferenceEntry {
1731
1734
start : file
1732
- . get_offset ( range. start . line as usize , range. start . character as usize ) ,
1735
+ . get_offset ( range. start . line as usize , range. start . character as usize )
1736
+ . unwrap ( ) ,
1733
1737
// 1 is added to account for the fact that `Lapper` expects half open ranges of the type: [`start`, `stop`)
1734
1738
// i.e, `start` included but `stop` excluded.
1735
- stop : file. get_offset ( range. end . line as usize , range. end . character as usize )
1739
+ stop : file
1740
+ . get_offset ( range. end . line as usize , range. end . character as usize )
1741
+ . unwrap ( )
1736
1742
+ 1 ,
1737
1743
val : di. clone ( ) ,
1738
1744
} ,
@@ -1761,7 +1767,9 @@ impl<'a> Builder<'a> {
1761
1767
. filter ( |h| h. 0 == i)
1762
1768
. map ( |( _, i) | {
1763
1769
let mut i = i. clone ( ) ;
1764
- i. val . def_path = defs_to_files[ & i. val . def_type ] . clone ( ) ;
1770
+ if let Some ( path) = defs_to_files. get ( & i. val . def_type ) {
1771
+ i. val . def_path = path. clone ( ) ;
1772
+ }
1765
1773
i
1766
1774
} )
1767
1775
. collect ( ) ,
@@ -1990,24 +1998,25 @@ impl LanguageServer for SolangServer {
1990
1998
if let Ok ( path) = uri. to_file_path ( ) {
1991
1999
let files = & self . files . lock ( ) . await ;
1992
2000
if let Some ( cache) = files. caches . get ( & path) {
1993
- let offset = cache
2001
+ if let Some ( offset) = cache
1994
2002
. file
1995
- . get_offset ( pos. line as usize , pos. character as usize ) ;
1996
-
1997
- // The shortest hover for the position will be most informative
1998
- if let Some ( hover) = cache
1999
- . hovers
2000
- . find ( offset, offset + 1 )
2001
- . min_by ( |a, b| ( a. stop - a. start ) . cmp ( & ( b. stop - b. start ) ) )
2003
+ . get_offset ( pos. line as usize , pos. character as usize )
2002
2004
{
2003
- let range = get_range_exclusive ( hover. start , hover. stop , & cache. file ) ;
2004
-
2005
- return Ok ( Some ( Hover {
2006
- contents : HoverContents :: Scalar ( MarkedString :: from_markdown (
2007
- hover. val . to_string ( ) ,
2008
- ) ) ,
2009
- range : Some ( range) ,
2010
- } ) ) ;
2005
+ // The shortest hover for the position will be most informative
2006
+ if let Some ( hover) = cache
2007
+ . hovers
2008
+ . find ( offset, offset + 1 )
2009
+ . min_by ( |a, b| ( a. stop - a. start ) . cmp ( & ( b. stop - b. start ) ) )
2010
+ {
2011
+ let range = get_range_exclusive ( hover. start , hover. stop , & cache. file ) ;
2012
+
2013
+ return Ok ( Some ( Hover {
2014
+ contents : HoverContents :: Scalar ( MarkedString :: from_markdown (
2015
+ hover. val . to_string ( ) ,
2016
+ ) ) ,
2017
+ range : Some ( range) ,
2018
+ } ) ) ;
2019
+ }
2011
2020
}
2012
2021
}
2013
2022
}
0 commit comments