microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
source/language_service/src/openqasm/definition.rs
34lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use std::sync::Arc; |
| 5 | |
| 6 | use log::trace; |
| 7 | use qsc::Span; |
| 8 | use qsc::line_column::{Encoding, Position}; |
| 9 | use qsc::location::Location; |
| 10 | |
| 11 | use crate::openqasm::map_spans_to_source_locations; |
| 12 | |
| 13 | pub fn get_definition( |
| 14 | sources: &[(Arc<str>, Arc<str>)], |
| 15 | source_name: &str, |
| 16 | position: Position, |
| 17 | position_encoding: Encoding, |
| 18 | ) -> Option<Location> { |
| 19 | let (res, id) = |
| 20 | super::find_symbol_in_sources(sources, source_name, position, position_encoding); |
| 21 | let id = id?; |
| 22 | let symbol = &res.symbols[id]; |
| 23 | trace!( |
| 24 | "get_definition: found symbol {} at {:?}", |
| 25 | symbol.name, symbol.span |
| 26 | ); |
| 27 | |
| 28 | // If the symbol is a built-in symbol, we can't go to def |
| 29 | if symbol.span == Span::default() { |
| 30 | return None; |
| 31 | } |
| 32 | |
| 33 | map_spans_to_source_locations(position_encoding, &res.source_map, vec![symbol.span]).pop() |
| 34 | } |
| 35 | |