microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.25.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/language_service/src/openqasm/definition.rs

34lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use std::sync::Arc;
5
6use log::trace;
7use qsc::Span;
8use qsc::line_column::{Encoding, Position};
9use qsc::location::Location;
10
11use crate::openqasm::map_spans_to_source_locations;
12
13pub 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