1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-23 12:03:30 +03:00

Remove unnecessary InFile wrapper

This commit is contained in:
oxalica 2022-08-07 17:38:52 +08:00
parent 17f917dd3f
commit 61819663d8
9 changed files with 17 additions and 19 deletions

View File

@ -34,13 +34,12 @@ pub trait SourceDatabase {
#[salsa::input]
fn file_content(&self, file_id: FileId) -> Arc<str>;
fn parse(&self, file_id: FileId) -> InFile<Parse>;
fn parse(&self, file_id: FileId) -> Parse;
}
fn parse(db: &dyn SourceDatabase, file_id: FileId) -> InFile<Parse> {
fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse {
let content = db.file_content(file_id);
let parse = syntax::parse_file(&content);
InFile::new(file_id, parse)
syntax::parse_file(&content)
}
#[derive(Default, Clone, PartialEq, Eq)]

View File

@ -2,7 +2,7 @@ use super::{
AstPtr, Attrpath, BindingKey, BindingValue, Bindings, Expr, ExprId, Literal, Module,
ModuleSourceMap, NameDef, NameDefId, NameDefKind, Pat, Path, PathAnchor,
};
use crate::{Diagnostic, DiagnosticKind, FileId, InFile};
use crate::{Diagnostic, DiagnosticKind, FileId};
use indexmap::IndexMap;
use la_arena::Arena;
use rowan::ast::AstNode;
@ -11,9 +11,9 @@ use std::{mem, str};
use syntax::ast::{self, HasBindings, HasStringParts, LiteralKind};
use syntax::{Parse, TextRange};
pub(super) fn lower(parse: InFile<Parse>) -> (Module, ModuleSourceMap) {
pub(super) fn lower(file_id: FileId, parse: Parse) -> (Module, ModuleSourceMap) {
let mut ctx = LowerCtx {
file_id: parse.file_id,
file_id,
module: Module {
exprs: Arena::new(),
name_defs: Arena::new(),
@ -24,7 +24,7 @@ pub(super) fn lower(parse: InFile<Parse>) -> (Module, ModuleSourceMap) {
source_map: ModuleSourceMap::default(),
};
let entry = ctx.lower_expr_opt(parse.value.root().expr());
let entry = ctx.lower_expr_opt(parse.root().expr());
let mut module = ctx.module;
module.entry_expr = entry;
(module, ctx.source_map)
@ -629,14 +629,14 @@ impl MergingEntry {
#[cfg(test)]
mod tests {
use super::lower;
use crate::base::{FileId, InFile};
use crate::base::FileId;
use expect_test::{expect, Expect};
use std::fmt::Write;
use syntax::parse_file;
fn check_lower(src: &str, expect: Expect) {
let parse = parse_file(src);
let (module, _source_map) = lower(InFile::new(FileId(0), parse));
let (module, _source_map) = lower(FileId(0), parse);
let mut got = String::new();
for diag in module.diagnostics() {
writeln!(got, "{:?}", diag).unwrap();
@ -658,7 +658,7 @@ mod tests {
fn check_error(src: &str, expect: Expect) {
let parse = parse_file(src);
let (module, _source_map) = lower(InFile::new(FileId(0), parse));
let (module, _source_map) = lower(FileId(0), parse);
let mut got = String::new();
for diag in module.diagnostics() {
writeln!(got, "{:?}", diag).unwrap();
@ -1241,6 +1241,6 @@ mod tests {
fn attrset_malformed_no_panic() {
let src = "{ } @ y: y { cc, extraPackages ? optional (cc.isGNU) }: 1";
let parse = parse_file(src);
let (_module, _source_map) = lower(InFile::new(FileId(0), parse));
let (_module, _source_map) = lower(FileId(0), parse);
}
}

View File

@ -39,7 +39,7 @@ fn module_with_source_map(
file_id: FileId,
) -> (Arc<Module>, Arc<ModuleSourceMap>) {
let parse = db.parse(file_id);
let (module, source_map) = lower::lower(parse);
let (module, source_map) = lower::lower(file_id, parse);
(Arc::new(module), Arc::new(source_map))
}

View File

@ -324,7 +324,7 @@ mod tests {
})
.expect("No Attr or Expr found");
let parse = db.parse(file_id).value;
let parse = db.parse(file_id);
let source_map = db.source_map(file_id);
let expr_id = source_map.expr_map[&ptr];
let got = db.resolve_name(file_id, expr_id).map(|ret| match ret {

View File

@ -29,7 +29,7 @@ pub(crate) fn completions(
file_id: FileId,
pos: TextSize,
) -> Option<Vec<CompletionItem>> {
let parse = db.parse(file_id).value;
let parse = db.parse(file_id);
let tok = parse.syntax_node().token_at_offset(pos).left_biased()?;
let source_range = match tok.kind() {

View File

@ -4,7 +4,7 @@ use crate::{Diagnostic, FileId};
const MAX_DIAGNOSTIC_CNT: usize = 128;
pub(crate) fn diagnostics(db: &dyn DefDatabase, file: FileId) -> Vec<Diagnostic> {
let parse = db.parse(file).value;
let parse = db.parse(file);
let module = db.module(file);
parse
.errors()

View File

@ -10,7 +10,7 @@ pub(crate) fn goto_definition(
file_id: FileId,
pos: TextSize,
) -> Option<Vec<NavigationTarget>> {
let parse = db.parse(file_id).value;
let parse = db.parse(file_id);
let tok = parse.syntax_node().token_at_offset(pos).right_biased()?;
if !matches!(tok.kind(), T![or] | SyntaxKind::IDENT) {
return None;

View File

@ -9,7 +9,7 @@ pub(crate) fn references(
file_id: FileId,
pos: TextSize,
) -> Option<Vec<FileRange>> {
let parse = db.parse(file_id).value;
let parse = db.parse(file_id);
let tok = parse.syntax_node().token_at_offset(pos).right_biased()?;
if !matches!(
tok.kind(),

View File

@ -41,7 +41,6 @@ impl TestDB {
f: impl FnMut(SyntaxNode) -> Option<T>,
) -> Option<T> {
self.parse(file_id)
.value
.syntax_node()
.token_at_offset(pos)
.right_biased()?