Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/hir-def/src/lang_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ pub enum GenericRequirement {

macro_rules! language_item_table {
(
$LangItems:ident =>
$( $(#[$attr:meta])* $lang_item:ident, $module:ident :: $name:ident, $method:ident, $target:ident, $generics:expr; )*
) => {
#[allow(non_snake_case)] // FIXME: Should we remove this?
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
pub struct LangItems {
pub struct $LangItems {
$(
$(#[$attr])*
pub $lang_item: Option<$target>,
Expand Down Expand Up @@ -219,7 +220,7 @@ macro_rules! language_item_table {
}
}

language_item_table! {
language_item_table! { LangItems =>
// Variant name, Name, Getter method name, Target Generic requirements;
Sized, sym::sized, sized_trait, TraitId, GenericRequirement::Exact(0);
MetaSized, sym::meta_sized, sized_trait, TraitId, GenericRequirement::Exact(0);
Expand Down
22 changes: 14 additions & 8 deletions crates/proc-macro-api/src/legacy_protocol/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ use crate::{ProcMacroKind, codec::Codec};
/// Represents requests sent from the client to the proc-macro-srv.
#[derive(Debug, Serialize, Deserialize)]
pub enum Request {
// IMPORTANT: Keep his first, otherwise postcard will break as its not a self describing format
// As such, this is the only request that needs to be supported across all protocol versions
// and by keeping it first, we ensure it always has the same discriminant encoding in postcard
/// Performs an API version check between the client and the server.
/// Since [`VERSION_CHECK_VERSION`]
ApiVersionCheck {},

/// Retrieves a list of macros from a given dynamic library.
/// Since [`NO_VERSION_CHECK_VERSION`]
ListMacros { dylib_path: Utf8PathBuf },
Expand All @@ -21,10 +28,6 @@ pub enum Request {
/// Since [`NO_VERSION_CHECK_VERSION`]
ExpandMacro(Box<ExpandMacro>),

/// Performs an API version check between the client and the server.
/// Since [`VERSION_CHECK_VERSION`]
ApiVersionCheck {},

/// Sets server-specific configurations.
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
SetConfig(ServerConfig),
Expand All @@ -44,6 +47,13 @@ pub enum SpanMode {
/// Represents responses sent from the proc-macro-srv to the client.
#[derive(Debug, Serialize, Deserialize)]
pub enum Response {
// IMPORTANT: Keep his first, otherwise postcard will break as its not a self describing format
// As such, this is the only request that needs to be supported across all protocol versions
// and by keeping it first, we ensure it always has the same discriminant encoding in postcard
/// Returns the API version supported by the server.
/// Since [`NO_VERSION_CHECK_VERSION`]
ApiVersionCheck(u32),

/// Returns a list of available macros in a dynamic library.
/// Since [`NO_VERSION_CHECK_VERSION`]
ListMacros(Result<Vec<(String, ProcMacroKind)>, String>),
Expand All @@ -52,10 +62,6 @@ pub enum Response {
/// Since [`NO_VERSION_CHECK_VERSION`]
ExpandMacro(Result<FlatTree, PanicMessage>),

/// Returns the API version supported by the server.
/// Since [`NO_VERSION_CHECK_VERSION`]
ApiVersionCheck(u32),

/// Confirms the application of a configuration update.
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
SetConfig(ServerConfig),
Expand Down
8 changes: 7 additions & 1 deletion crates/proc-macro-srv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ impl ProcMacroSrvSpan for SpanId {
type Server = server_impl::token_id::SpanIdServer;

fn make_server(call_site: Self, def_site: Self, mixed_site: Self) -> Self::Server {
Self::Server { call_site, def_site, mixed_site }
Self::Server {
call_site,
def_site,
mixed_site,
tracked_env_vars: Default::default(),
tracked_paths: Default::default(),
}
}
}
impl ProcMacroSrvSpan for Span {
Expand Down
18 changes: 15 additions & 3 deletions crates/proc-macro-srv/src/server_impl/token_id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! proc-macro server backend based on [`proc_macro_api::msg::SpanId`] as the backing span.
//! This backend is rather inflexible, used by RustRover and older rust-analyzer versions.
use std::ops::{Bound, Range};
use std::{
collections::{HashMap, HashSet},
ops::{Bound, Range},
};

use intern::Symbol;
use proc_macro::bridge::server;
Expand All @@ -24,6 +27,10 @@ type Span = SpanId;
pub struct FreeFunctions;

pub struct SpanIdServer {
// FIXME: Report this back to the caller to track as dependencies
pub tracked_env_vars: HashMap<Box<str>, Option<Box<str>>>,
// FIXME: Report this back to the caller to track as dependencies
pub tracked_paths: HashSet<Box<str>>,
pub call_site: Span,
pub def_site: Span,
pub mixed_site: Span,
Expand All @@ -40,8 +47,13 @@ impl server::FreeFunctions for SpanIdServer {
fn injected_env_var(&mut self, _: &str) -> Option<std::string::String> {
None
}
fn track_env_var(&mut self, _var: &str, _value: Option<&str>) {}
fn track_path(&mut self, _path: &str) {}
fn track_env_var(&mut self, var: &str, value: Option<&str>) {
self.tracked_env_vars.insert(var.into(), value.map(Into::into));
}
fn track_path(&mut self, path: &str) {
self.tracked_paths.insert(path.into());
}

fn literal_from_str(&mut self, s: &str) -> Result<Literal<Self::Span>, ()> {
literal_from_str(s, self.call_site)
}
Expand Down