mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Move Edition into span crate
This commit is contained in:
parent
8d74705b43
commit
255a8aef92
21 changed files with 103 additions and 101 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -594,6 +594,7 @@ dependencies = [
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"scoped-tls",
|
"scoped-tls",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
"span",
|
||||||
"stdx",
|
"stdx",
|
||||||
"syntax",
|
"syntax",
|
||||||
"test-fixture",
|
"test-fixture",
|
||||||
|
@ -637,6 +638,7 @@ dependencies = [
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
"pulldown-cmark-to-cmark",
|
"pulldown-cmark-to-cmark",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
"span",
|
||||||
"stdx",
|
"stdx",
|
||||||
"syntax",
|
"syntax",
|
||||||
"test-fixture",
|
"test-fixture",
|
||||||
|
@ -1380,6 +1382,7 @@ dependencies = [
|
||||||
"semver",
|
"semver",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"span",
|
||||||
"stdx",
|
"stdx",
|
||||||
"toolchain",
|
"toolchain",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
|
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
|
||||||
//! actual IO is done and lowered to input.
|
//! actual IO is done and lowered to input.
|
||||||
|
|
||||||
use std::{fmt, mem, ops, str::FromStr};
|
use std::{fmt, mem, ops};
|
||||||
|
|
||||||
use cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
use la_arena::{Arena, Idx, RawIdx};
|
use la_arena::{Arena, Idx, RawIdx};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
use span::Edition;
|
||||||
use syntax::SmolStr;
|
use syntax::SmolStr;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
|
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
|
||||||
|
@ -293,42 +294,11 @@ pub struct CrateData {
|
||||||
pub is_proc_macro: bool,
|
pub is_proc_macro: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub enum Edition {
|
|
||||||
Edition2015,
|
|
||||||
Edition2018,
|
|
||||||
Edition2021,
|
|
||||||
Edition2024,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Edition {
|
|
||||||
pub const CURRENT: Edition = Edition::Edition2021;
|
|
||||||
pub const DEFAULT: Edition = Edition::Edition2015;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Env {
|
pub struct Env {
|
||||||
entries: FxHashMap<String, String>,
|
entries: FxHashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Env {
|
|
||||||
pub fn new_for_test_fixture() -> Self {
|
|
||||||
Env {
|
|
||||||
entries: FxHashMap::from_iter([(
|
|
||||||
String::from("__ra_is_test_fixture"),
|
|
||||||
String::from("__ra_is_test_fixture"),
|
|
||||||
)]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub enum DependencyKind {
|
|
||||||
Normal,
|
|
||||||
Dev,
|
|
||||||
Build,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Dependency {
|
pub struct Dependency {
|
||||||
pub crate_id: CrateId,
|
pub crate_id: CrateId,
|
||||||
|
@ -670,32 +640,6 @@ impl CrateData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Edition {
|
|
||||||
type Err = ParseEditionError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
let res = match s {
|
|
||||||
"2015" => Edition::Edition2015,
|
|
||||||
"2018" => Edition::Edition2018,
|
|
||||||
"2021" => Edition::Edition2021,
|
|
||||||
"2024" => Edition::Edition2024,
|
|
||||||
_ => return Err(ParseEditionError { invalid_input: s.to_owned() }),
|
|
||||||
};
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Edition {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str(match self {
|
|
||||||
Edition::Edition2015 => "2015",
|
|
||||||
Edition::Edition2018 => "2018",
|
|
||||||
Edition::Edition2021 => "2021",
|
|
||||||
Edition::Edition2024 => "2024",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Extend<(String, String)> for Env {
|
impl Extend<(String, String)> for Env {
|
||||||
fn extend<T: IntoIterator<Item = (String, String)>>(&mut self, iter: T) {
|
fn extend<T: IntoIterator<Item = (String, String)>>(&mut self, iter: T) {
|
||||||
self.entries.extend(iter);
|
self.entries.extend(iter);
|
||||||
|
@ -722,19 +666,6 @@ impl Env {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ParseEditionError {
|
|
||||||
invalid_input: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for ParseEditionError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "invalid edition: {:?}", self.invalid_input)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::error::Error for ParseEditionError {}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CyclicDependenciesError {
|
pub struct CyclicDependenciesError {
|
||||||
path: Vec<(CrateId, Option<CrateDisplayName>)>,
|
path: Vec<(CrateId, Option<CrateDisplayName>)>,
|
||||||
|
|
|
@ -14,9 +14,9 @@ use triomphe::Arc;
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
change::FileChange,
|
change::FileChange,
|
||||||
input::{
|
input::{
|
||||||
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency,
|
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env,
|
||||||
DependencyKind, Edition, Env, LangCrateOrigin, ProcMacroPaths, ReleaseChannel, SourceRoot,
|
LangCrateOrigin, ProcMacroPaths, ReleaseChannel, SourceRoot, SourceRootId,
|
||||||
SourceRootId, TargetLayoutLoadResult,
|
TargetLayoutLoadResult,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
pub use salsa::{self, Cancelled};
|
pub use salsa::{self, Cancelled};
|
||||||
|
|
|
@ -73,7 +73,7 @@ use std::{
|
||||||
use base_db::{
|
use base_db::{
|
||||||
impl_intern_key,
|
impl_intern_key,
|
||||||
salsa::{self, impl_intern_value_trivial},
|
salsa::{self, impl_intern_value_trivial},
|
||||||
CrateId, Edition,
|
CrateId,
|
||||||
};
|
};
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
builtin_attr_macro::BuiltinAttrExpander,
|
builtin_attr_macro::BuiltinAttrExpander,
|
||||||
|
@ -90,7 +90,7 @@ use hir_expand::{
|
||||||
use item_tree::ExternBlock;
|
use item_tree::ExternBlock;
|
||||||
use la_arena::Idx;
|
use la_arena::Idx;
|
||||||
use nameres::DefMap;
|
use nameres::DefMap;
|
||||||
use span::{AstIdNode, FileAstId, FileId, SyntaxContextId};
|
use span::{AstIdNode, Edition, FileAstId, FileId, SyntaxContextId};
|
||||||
use stdx::impl_from;
|
use stdx::impl_from;
|
||||||
use syntax::{ast, AstNode};
|
use syntax::{ast, AstNode};
|
||||||
|
|
||||||
|
|
|
@ -59,14 +59,14 @@ mod tests;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use base_db::{CrateId, Edition, FileId};
|
use base_db::{CrateId, FileId};
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
name::Name, proc_macro::ProcMacroKind, ErasedAstId, HirFileId, InFile, MacroCallId, MacroDefId,
|
name::Name, proc_macro::ProcMacroKind, ErasedAstId, HirFileId, InFile, MacroCallId, MacroDefId,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use la_arena::Arena;
|
use la_arena::Arena;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use span::{FileAstId, ROOT_ERASED_FILE_AST_ID};
|
use span::{Edition, FileAstId, ROOT_ERASED_FILE_AST_ID};
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
use syntax::{ast, SmolStr};
|
use syntax::{ast, SmolStr};
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use std::{cmp::Ordering, iter, mem, ops::Not};
|
use std::{cmp::Ordering, iter, mem, ops::Not};
|
||||||
|
|
||||||
use base_db::{CrateId, Dependency, Edition, FileId};
|
use base_db::{CrateId, Dependency, FileId};
|
||||||
use cfg::{CfgExpr, CfgOptions};
|
use cfg::{CfgExpr, CfgOptions};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
|
@ -22,7 +22,7 @@ use itertools::{izip, Itertools};
|
||||||
use la_arena::Idx;
|
use la_arena::Idx;
|
||||||
use limit::Limit;
|
use limit::Limit;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use span::{ErasedFileAstId, FileAstId, Span, SyntaxContextId};
|
use span::{Edition, ErasedFileAstId, FileAstId, Span, SyntaxContextId};
|
||||||
use stdx::always;
|
use stdx::always;
|
||||||
use syntax::{ast, SmolStr};
|
use syntax::{ast, SmolStr};
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
//!
|
//!
|
||||||
//! `ReachedFixedPoint` signals about this.
|
//! `ReachedFixedPoint` signals about this.
|
||||||
|
|
||||||
use base_db::Edition;
|
|
||||||
use hir_expand::{name::Name, Lookup};
|
use hir_expand::{name::Name, Lookup};
|
||||||
|
use span::Edition;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
//! Builtin macro
|
//! Builtin macro
|
||||||
|
|
||||||
use base_db::{AnchoredPath, Edition, FileId};
|
use base_db::{AnchoredPath, FileId};
|
||||||
use cfg::CfgExpr;
|
use cfg::CfgExpr;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
|
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
|
||||||
use span::{Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
|
use span::{Edition, Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
|
||||||
use syntax::ast::{self, AstToken};
|
use syntax::ast::{self, AstToken};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
//! Compiled declarative macro expanders (`macro_rules!`` and `macro`)
|
//! Compiled declarative macro expanders (`macro_rules!`` and `macro`)
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use base_db::{CrateId, Edition, VersionReq};
|
use base_db::{CrateId, VersionReq};
|
||||||
use span::{MacroCallId, Span};
|
use span::{Edition, MacroCallId, Span};
|
||||||
use syntax::{ast, AstNode};
|
use syntax::{ast, AstNode};
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,11 @@ use triomphe::Arc;
|
||||||
|
|
||||||
use std::{fmt, hash::Hash};
|
use std::{fmt, hash::Hash};
|
||||||
|
|
||||||
use base_db::{salsa::impl_intern_value_trivial, CrateId, Edition, FileId};
|
use base_db::{salsa::impl_intern_value_trivial, CrateId, FileId};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use span::{
|
use span::{
|
||||||
ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData, SyntaxContextId,
|
Edition, ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData,
|
||||||
|
SyntaxContextId,
|
||||||
};
|
};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
|
|
|
@ -47,6 +47,7 @@ hir-expand.workspace = true
|
||||||
base-db.workspace = true
|
base-db.workspace = true
|
||||||
syntax.workspace = true
|
syntax.workspace = true
|
||||||
limit.workspace = true
|
limit.workspace = true
|
||||||
|
span.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
expect-test = "1.4.0"
|
expect-test = "1.4.0"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs.
|
//! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs.
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
use base_db::{CrateId, Edition};
|
use base_db::CrateId;
|
||||||
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
|
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
data::{adt::StructFlags, ImplData},
|
data::{adt::StructFlags, ImplData},
|
||||||
|
@ -15,6 +15,7 @@ use hir_def::{
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
use span::Edition;
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ mod display;
|
||||||
use std::{iter, mem::discriminant, ops::ControlFlow};
|
use std::{iter, mem::discriminant, ops::ControlFlow};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId};
|
use base_db::{CrateDisplayName, CrateId, CrateOrigin, FileId};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::{BodyDiagnostic, SyntheticSyntax},
|
body::{BodyDiagnostic, SyntheticSyntax},
|
||||||
|
@ -79,6 +79,7 @@ use hir_ty::{
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nameres::diagnostics::DefDiagnosticKind;
|
use nameres::diagnostics::DefDiagnosticKind;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
use span::Edition;
|
||||||
use stdx::{impl_from, never};
|
use stdx::{impl_from, never};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, HasAttrs as _, HasName},
|
ast::{self, HasAttrs as _, HasName},
|
||||||
|
|
|
@ -36,6 +36,7 @@ ide-ssr.workspace = true
|
||||||
profile.workspace = true
|
profile.workspace = true
|
||||||
stdx.workspace = true
|
stdx.workspace = true
|
||||||
syntax.workspace = true
|
syntax.workspace = true
|
||||||
|
span.workspace = true
|
||||||
text-edit.workspace = true
|
text-edit.workspace = true
|
||||||
# ide should depend only on the top-level `hir` package. if you need
|
# ide should depend only on the top-level `hir` package. if you need
|
||||||
# something from some `hir-xxx` subpackage, reexport the API via `hir`.
|
# something from some `hir-xxx` subpackage, reexport the API via `hir`.
|
||||||
|
|
|
@ -119,8 +119,8 @@ pub use ide_completion::{
|
||||||
};
|
};
|
||||||
pub use ide_db::{
|
pub use ide_db::{
|
||||||
base_db::{
|
base_db::{
|
||||||
Cancelled, CrateGraph, CrateId, Edition, FileChange, FileId, FilePosition, FileRange,
|
Cancelled, CrateGraph, CrateId, FileChange, FileId, FilePosition, FileRange, SourceRoot,
|
||||||
SourceRoot, SourceRootId,
|
SourceRootId,
|
||||||
},
|
},
|
||||||
documentation::Documentation,
|
documentation::Documentation,
|
||||||
label::Label,
|
label::Label,
|
||||||
|
@ -135,6 +135,7 @@ pub use ide_diagnostics::{
|
||||||
Diagnostic, DiagnosticCode, DiagnosticsConfig, ExprFillDefaultMode, Severity,
|
Diagnostic, DiagnosticCode, DiagnosticsConfig, ExprFillDefaultMode, Severity,
|
||||||
};
|
};
|
||||||
pub use ide_ssr::SsrError;
|
pub use ide_ssr::SsrError;
|
||||||
|
pub use span::Edition;
|
||||||
pub use syntax::{TextRange, TextSize};
|
pub use syntax::{TextRange, TextSize};
|
||||||
pub use text_edit::{Indel, TextEdit};
|
pub use text_edit::{Indel, TextEdit};
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ itertools.workspace = true
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
base-db.workspace = true
|
base-db.workspace = true
|
||||||
|
span.workspace = true
|
||||||
cfg.workspace = true
|
cfg.workspace = true
|
||||||
paths = { workspace = true, features = ["serde1"] }
|
paths = { workspace = true, features = ["serde1"] }
|
||||||
stdx.workspace = true
|
stdx.workspace = true
|
||||||
|
|
|
@ -4,13 +4,13 @@ use std::ops;
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use base_db::Edition;
|
|
||||||
use cargo_metadata::{CargoOpt, MetadataCommand};
|
use cargo_metadata::{CargoOpt, MetadataCommand};
|
||||||
use la_arena::{Arena, Idx};
|
use la_arena::{Arena, Idx};
|
||||||
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
|
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::from_value;
|
use serde_json::from_value;
|
||||||
|
use span::Edition;
|
||||||
use toolchain::Tool;
|
use toolchain::Tool;
|
||||||
|
|
||||||
use crate::{utf8_stdout, InvocationLocation, ManifestPath, Sysroot};
|
use crate::{utf8_stdout, InvocationLocation, ManifestPath, Sysroot};
|
||||||
|
|
|
@ -49,11 +49,12 @@
|
||||||
//! user explores them belongs to that extension (it's totally valid to change
|
//! user explores them belongs to that extension (it's totally valid to change
|
||||||
//! rust-project.json over time via configuration request!)
|
//! rust-project.json over time via configuration request!)
|
||||||
|
|
||||||
use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition};
|
use base_db::{CrateDisplayName, CrateId, CrateName, Dependency};
|
||||||
use la_arena::RawIdx;
|
use la_arena::RawIdx;
|
||||||
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
|
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::{de, Deserialize};
|
use serde::{de, Deserialize};
|
||||||
|
use span::Edition;
|
||||||
|
|
||||||
use crate::cfg_flag::CfgFlag;
|
use crate::cfg_flag::CfgFlag;
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,14 @@ use std::{collections::VecDeque, fmt, fs, iter, str::FromStr, sync};
|
||||||
|
|
||||||
use anyhow::{format_err, Context};
|
use anyhow::{format_err, Context};
|
||||||
use base_db::{
|
use base_db::{
|
||||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
|
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env, FileId,
|
||||||
FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
|
LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
|
||||||
};
|
};
|
||||||
use cfg::{CfgAtom, CfgDiff, CfgOptions};
|
use cfg::{CfgAtom, CfgDiff, CfgOptions};
|
||||||
use paths::{AbsPath, AbsPathBuf};
|
use paths::{AbsPath, AbsPathBuf};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
use span::Edition;
|
||||||
use stdx::always;
|
use stdx::always;
|
||||||
use toolchain::Tool;
|
use toolchain::Tool;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
|
@ -16,6 +16,56 @@ pub use self::{
|
||||||
pub use syntax::{TextRange, TextSize};
|
pub use syntax::{TextRange, TextSize};
|
||||||
pub use vfs::FileId;
|
pub use vfs::FileId;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub enum Edition {
|
||||||
|
Edition2015,
|
||||||
|
Edition2018,
|
||||||
|
Edition2021,
|
||||||
|
Edition2024,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Edition {
|
||||||
|
pub const CURRENT: Edition = Edition::Edition2021;
|
||||||
|
pub const DEFAULT: Edition = Edition::Edition2015;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ParseEditionError {
|
||||||
|
invalid_input: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for ParseEditionError {}
|
||||||
|
impl fmt::Display for ParseEditionError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "invalid edition: {:?}", self.invalid_input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::str::FromStr for Edition {
|
||||||
|
type Err = ParseEditionError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
let res = match s {
|
||||||
|
"2015" => Edition::Edition2015,
|
||||||
|
"2018" => Edition::Edition2018,
|
||||||
|
"2021" => Edition::Edition2021,
|
||||||
|
"2024" => Edition::Edition2024,
|
||||||
|
_ => return Err(ParseEditionError { invalid_input: s.to_owned() }),
|
||||||
|
};
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Edition {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
Edition::Edition2015 => "2015",
|
||||||
|
Edition::Edition2018 => "2018",
|
||||||
|
Edition::Edition2021 => "2021",
|
||||||
|
Edition::Edition2024 => "2024",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct FilePosition {
|
pub struct FilePosition {
|
||||||
pub file_id: FileId,
|
pub file_id: FileId,
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
use std::{iter, mem, ops::Not, str::FromStr, sync};
|
use std::{iter, mem, ops::Not, str::FromStr, sync};
|
||||||
|
|
||||||
use base_db::{
|
use base_db::{
|
||||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
|
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env, FileChange,
|
||||||
FileChange, FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version, VfsPath,
|
FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version, VfsPath,
|
||||||
};
|
};
|
||||||
use cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
|
@ -14,7 +14,7 @@ use hir_expand::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use span::{FileId, FilePosition, FileRange, Span};
|
use span::{Edition, FileId, FilePosition, FileRange, Span};
|
||||||
use test_utils::{
|
use test_utils::{
|
||||||
extract_range_or_offset, Fixture, FixtureWithProjectMeta, RangeOrOffset, CURSOR_MARKER,
|
extract_range_or_offset, Fixture, FixtureWithProjectMeta, RangeOrOffset, CURSOR_MARKER,
|
||||||
ESCAPED_CURSOR_MARKER,
|
ESCAPED_CURSOR_MARKER,
|
||||||
|
@ -137,7 +137,10 @@ impl ChangeFixture {
|
||||||
let mut crate_deps = Vec::new();
|
let mut crate_deps = Vec::new();
|
||||||
let mut default_crate_root: Option<FileId> = None;
|
let mut default_crate_root: Option<FileId> = None;
|
||||||
let mut default_cfg = CfgOptions::default();
|
let mut default_cfg = CfgOptions::default();
|
||||||
let mut default_env = Env::new_for_test_fixture();
|
let mut default_env = Env::from_iter([(
|
||||||
|
String::from("__ra_is_test_fixture"),
|
||||||
|
String::from("__ra_is_test_fixture"),
|
||||||
|
)]);
|
||||||
|
|
||||||
let mut file_set = FileSet::default();
|
let mut file_set = FileSet::default();
|
||||||
let mut current_source_root_kind = SourceRootKind::Local;
|
let mut current_source_root_kind = SourceRootKind::Local;
|
||||||
|
@ -262,7 +265,10 @@ impl ChangeFixture {
|
||||||
None,
|
None,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Env::new_for_test_fixture(),
|
Env::from_iter([(
|
||||||
|
String::from("__ra_is_test_fixture"),
|
||||||
|
String::from("__ra_is_test_fixture"),
|
||||||
|
)]),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::Lang(LangCrateOrigin::Core),
|
CrateOrigin::Lang(LangCrateOrigin::Core),
|
||||||
);
|
);
|
||||||
|
@ -298,7 +304,10 @@ impl ChangeFixture {
|
||||||
None,
|
None,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Env::new_for_test_fixture(),
|
Env::from_iter([(
|
||||||
|
String::from("__ra_is_test_fixture"),
|
||||||
|
String::from("__ra_is_test_fixture"),
|
||||||
|
)]),
|
||||||
true,
|
true,
|
||||||
CrateOrigin::Local { repo: None, name: None },
|
CrateOrigin::Local { repo: None, name: None },
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue