mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
stub missing APIs
This commit is contained in:
parent
00bc060ba3
commit
191db9fed4
3 changed files with 56 additions and 25 deletions
|
@ -14,12 +14,13 @@ use super::proc_macro::{
|
||||||
};
|
};
|
||||||
|
|
||||||
mod token_stream;
|
mod token_stream;
|
||||||
pub use token_stream::*;
|
pub use token_stream::TokenStream;
|
||||||
|
use token_stream::TokenStreamBuilder;
|
||||||
|
|
||||||
mod symbol;
|
mod symbol;
|
||||||
pub use symbol::*;
|
pub use symbol::*;
|
||||||
|
|
||||||
use std::iter::FromIterator;
|
use std::{iter::FromIterator, ops::Bound};
|
||||||
|
|
||||||
type Group = tt::Subtree;
|
type Group = tt::Subtree;
|
||||||
type TokenTree = tt::TokenTree;
|
type TokenTree = tt::TokenTree;
|
||||||
|
@ -76,6 +77,13 @@ impl server::FreeFunctions for RustAnalyzer {
|
||||||
// https://github.com/rust-lang/rust/pull/71858
|
// https://github.com/rust-lang/rust/pull/71858
|
||||||
}
|
}
|
||||||
fn track_path(&mut self, _path: &str) {}
|
fn track_path(&mut self, _path: &str) {}
|
||||||
|
|
||||||
|
fn literal_from_str(
|
||||||
|
&mut self,
|
||||||
|
_s: &str,
|
||||||
|
) -> Result<bridge::Literal<Self::Span, Self::Symbol>, ()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl server::TokenStream for RustAnalyzer {
|
impl server::TokenStream for RustAnalyzer {
|
||||||
|
@ -92,7 +100,7 @@ impl server::TokenStream for RustAnalyzer {
|
||||||
}
|
}
|
||||||
fn from_token_tree(
|
fn from_token_tree(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: bridge::TokenTree<Self::TokenStream, Self::Span, Self::Ident, Self::Literal>,
|
tree: bridge::TokenTree<Self::TokenStream, Self::Span, Self::Symbol>,
|
||||||
) -> Self::TokenStream {
|
) -> Self::TokenStream {
|
||||||
match tree {
|
match tree {
|
||||||
bridge::TokenTree::Group(group) => {
|
bridge::TokenTree::Group(group) => {
|
||||||
|
@ -107,8 +115,8 @@ impl server::TokenStream for RustAnalyzer {
|
||||||
Self::TokenStream::from_iter(vec![tree])
|
Self::TokenStream::from_iter(vec![tree])
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge::TokenTree::Ident(symbol) => {
|
bridge::TokenTree::Ident(_symbol) => {
|
||||||
todo!("implement");
|
todo!("convert Ident bridge=>TokenStream");
|
||||||
// let IdentData(ident) = self.ident_interner.get(index).clone();
|
// let IdentData(ident) = self.ident_interner.get(index).clone();
|
||||||
// let ident: tt::Ident = ident;
|
// let ident: tt::Ident = ident;
|
||||||
// let leaf = tt::Leaf::from(ident);
|
// let leaf = tt::Leaf::from(ident);
|
||||||
|
@ -116,10 +124,11 @@ impl server::TokenStream for RustAnalyzer {
|
||||||
// Self::TokenStream::from_iter(vec![tree])
|
// Self::TokenStream::from_iter(vec![tree])
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge::TokenTree::Literal(literal) => {
|
bridge::TokenTree::Literal(_literal) => {
|
||||||
let leaf = tt::Leaf::from(literal);
|
todo!("convert Literal bridge=>TokenStream");
|
||||||
let tree = TokenTree::from(leaf);
|
// let leaf = tt::Leaf::from(literal);
|
||||||
Self::TokenStream::from_iter(vec![tree])
|
// let tree = TokenTree::from(leaf);
|
||||||
|
// Self::TokenStream::from_iter(vec![tree])
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge::TokenTree::Punct(p) => {
|
bridge::TokenTree::Punct(p) => {
|
||||||
|
@ -142,7 +151,7 @@ impl server::TokenStream for RustAnalyzer {
|
||||||
fn concat_trees(
|
fn concat_trees(
|
||||||
&mut self,
|
&mut self,
|
||||||
base: Option<Self::TokenStream>,
|
base: Option<Self::TokenStream>,
|
||||||
trees: Vec<bridge::TokenTree<Self::TokenStream, Self::Span, Self::Ident, Self::Literal>>,
|
trees: Vec<bridge::TokenTree<Self::TokenStream, Self::Span, Self::Symbol>>,
|
||||||
) -> Self::TokenStream {
|
) -> Self::TokenStream {
|
||||||
let mut builder = TokenStreamBuilder::new();
|
let mut builder = TokenStreamBuilder::new();
|
||||||
if let Some(base) = base {
|
if let Some(base) = base {
|
||||||
|
@ -172,15 +181,18 @@ impl server::TokenStream for RustAnalyzer {
|
||||||
fn into_trees(
|
fn into_trees(
|
||||||
&mut self,
|
&mut self,
|
||||||
stream: Self::TokenStream,
|
stream: Self::TokenStream,
|
||||||
) -> Vec<bridge::TokenTree<Self::TokenStream, Self::Span, Self::Ident, Self::Literal>> {
|
) -> Vec<bridge::TokenTree<Self::TokenStream, Self::Span, Self::Symbol>> {
|
||||||
stream
|
stream
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|tree| match tree {
|
.map(|tree| match tree {
|
||||||
tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => {
|
tt::TokenTree::Leaf(tt::Leaf::Ident(_ident)) => {
|
||||||
todo!("implement");
|
todo!("convert Ident tt=>bridge");
|
||||||
// bridge::TokenTree::Ident(Symbol(self.ident_interner.intern(&IdentData(ident))))
|
// bridge::TokenTree::Ident(Symbol(self.ident_interner.intern(&IdentData(ident))))
|
||||||
}
|
}
|
||||||
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => bridge::TokenTree::Literal(lit),
|
tt::TokenTree::Leaf(tt::Leaf::Literal(_lit)) => {
|
||||||
|
todo!("convert Literal tt=>bridge");
|
||||||
|
// bridge::TokenTree::Literal(lit)
|
||||||
|
}
|
||||||
tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) => {
|
tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) => {
|
||||||
bridge::TokenTree::Punct(bridge::Punct {
|
bridge::TokenTree::Punct(bridge::Punct {
|
||||||
ch: punct.char as u8,
|
ch: punct.char as u8,
|
||||||
|
@ -317,6 +329,15 @@ impl server::Span for RustAnalyzer {
|
||||||
// Just return the first span again, because some macros will unwrap the result.
|
// Just return the first span again, because some macros will unwrap the result.
|
||||||
Some(first)
|
Some(first)
|
||||||
}
|
}
|
||||||
|
fn subspan(
|
||||||
|
&mut self,
|
||||||
|
span: Self::Span,
|
||||||
|
_start: Bound<usize>,
|
||||||
|
_end: Bound<usize>,
|
||||||
|
) -> Option<Self::Span> {
|
||||||
|
// Just return the span again, because some macros will unwrap the result.
|
||||||
|
Some(span)
|
||||||
|
}
|
||||||
fn resolved_at(&mut self, _span: Self::Span, _at: Self::Span) -> Self::Span {
|
fn resolved_at(&mut self, _span: Self::Span, _at: Self::Span) -> Self::Span {
|
||||||
// FIXME handle span
|
// FIXME handle span
|
||||||
tt::TokenId::unspecified()
|
tt::TokenId::unspecified()
|
||||||
|
@ -343,6 +364,12 @@ impl server::MultiSpan for RustAnalyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl server::Symbol for RustAnalyzer {
|
||||||
|
fn normalize_and_validate_ident(&mut self, _string: &str) -> Result<Self::Symbol, ()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl server::Server for RustAnalyzer {
|
impl server::Server for RustAnalyzer {
|
||||||
fn globals(&mut self) -> bridge::ExpnGlobals<Self::Span> {
|
fn globals(&mut self) -> bridge::ExpnGlobals<Self::Span> {
|
||||||
bridge::ExpnGlobals {
|
bridge::ExpnGlobals {
|
||||||
|
@ -351,6 +378,14 @@ impl server::Server for RustAnalyzer {
|
||||||
mixed_site: Span::unspecified(),
|
mixed_site: Span::unspecified(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn intern_symbol(_ident: &str) -> Self::Symbol {
|
||||||
|
todo!("intern_symbol")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with_symbol_string(_symbol: &Self::Symbol, _f: impl FnOnce(&str)) {
|
||||||
|
todo!("with_symbol_string")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -14,13 +14,14 @@ struct IdentInterner {
|
||||||
impl IdentInterner {
|
impl IdentInterner {
|
||||||
fn intern(&mut self, data: &str) -> Symbol {
|
fn intern(&mut self, data: &str) -> Symbol {
|
||||||
if let Some(index) = self.idents.get(data) {
|
if let Some(index) = self.idents.get(data) {
|
||||||
return *index;
|
return Symbol(*index);
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = self.idents.len() as u32;
|
let index = self.idents.len() as u32;
|
||||||
|
let data = SmolStr::from(data);
|
||||||
self.ident_data.push(data.clone());
|
self.ident_data.push(data.clone());
|
||||||
self.idents.insert(data.clone(), index);
|
self.idents.insert(data, index);
|
||||||
index
|
Symbol(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self, index: u32) -> &SmolStr {
|
fn get(&self, index: u32) -> &SmolStr {
|
||||||
|
|
|
@ -163,20 +163,15 @@ pub mod token_stream {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TokenStreamBuilder {
|
impl TokenStreamBuilder {
|
||||||
fn new() -> TokenStreamBuilder {
|
pub(super) fn new() -> TokenStreamBuilder {
|
||||||
TokenStreamBuilder { acc: TokenStream::new() }
|
TokenStreamBuilder { acc: TokenStream::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push(&mut self, stream: TokenStream) {
|
pub(super) fn push(&mut self, stream: TokenStream) {
|
||||||
self.acc.extend(stream.into_iter())
|
self.acc.extend(stream.into_iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(self) -> TokenStream {
|
pub(super) fn build(self) -> TokenStream {
|
||||||
self.acc
|
self.acc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct TokenStreamIter {
|
|
||||||
trees: std::vec::IntoIter<TokenTree>,
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue