pub async fn goto_definition(
        &self,
        uri: &Url,
        position: lsp::Position,
    ) -> Option<lsp::Location> {
        let sources = self.inner.sources.read().await;

        let source = sources.get(uri)?;
        let offset = source.lsp_position_to_offset(position);
        let def = source.find_definition_at(Span::point(offset))?;

        let url = match def.source.path.as_ref() {
            Some(path) => Url::from_file_path(path).ok()?,
            None => uri.clone(),
        };

        let source = source.build_sources.as_ref()?.get(def.source.source_id)?;

        let (l, c) = source.position_to_utf16cu_line_char(def.source.span.start.into_usize())?;
        let start = lsp::Position {
            line: l as u32,
            character: c as u32,
        };

        let (l, c) = source.position_to_utf16cu_line_char(def.source.span.end.into_usize())?;
        let end = lsp::Position {
            line: l as u32,
            character: c as u32,
        };

        let range = lsp::Range { start, end };

        let location = lsp::Location { uri: url, range };

        log::trace!("go to location: {:?}", location);
        Some(location)
    }
/// Find definition at the given uri and LSP position.
Find definition at the given uri and LSP position.
Find definition at the given uri and LSP position .
pub async fn goto_definition(
        &self,
        uri: &Url,
        position: lsp::Position,
    ) -> Option<lsp::Location> {
        let sources = self.inner.sources.read().await;
        let source = sources.get(uri)?;
        let offset = source.lsp_position_to_offset(position);
        let def = source.find_definition_at(Span::point(offset))?;
        let url = match def.source.path.as_ref() {
            Some(path) => Url::from_file_path(path).ok()?,
            None => uri.clone(),
        };
        let source = source.build_sources.as_ref()?.get(def.source.source_id)?;
        let (l, c) = source.position_to_utf16cu_line_char(def.source.span.start.into_usize())?;
        let start = lsp::Position {
            line: l as u32,
            character: c as u32,
        };
        let (l, c) = source.position_to_utf16cu_line_char(def.source.span.end.into_usize())?;
        let end = lsp::Position {
            line: l as u32,
            character: c as u32,
        };
        let range = lsp::Range { start, end };
        let location = lsp::Location { uri: url, range };
        log::trace!("go to location: {:?}", location);
        Some(location)
    }
pub async fn goto_definition ( & self , uri : & Url , position : lsp :: Position , ) -> Option < lsp :: Location > { let sources = self . inner . sources . read ( ) . await ; let source = sources . get ( uri ) ? ; let offset = source . lsp_position_to_offset ( position ) ; let def = source . find_definition_at ( Span :: point ( offset ) ) ? ; let url = match def . source . path . as_ref ( ) { Some ( path ) => Url :: from_file_path ( path ) . ok ( ) ? , None => uri . clone ( ) , } ; let source = source . build_sources . as_ref ( ) ? . get ( def . source . source_id ) ? ; let ( l , c ) = source . position_to_utf16cu_line_char ( def . source . span . start . into_usize ( ) ) ? ; let start = lsp :: Position { line : l as u32 , character : c as u32 , } ; let ( l , c ) = source . position_to_utf16cu_line_char ( def . source . span . end . into_usize ( ) ) ? ; let end = lsp :: Position { line : l as u32 , character : c as u32 , } ; let range = lsp :: Range { start , end } ; let location = lsp :: Location { uri : url , range } ; log :: trace ! ( " " location ) ; Some ( location ) }
Find definition at the given uri and LSP position.
Find definition at the given uri and LSP position .
&self
uri
&Url
position
lsp::Position
&self
uri
&Url
position
lsp::Position