Skip to content

Commit

Permalink
12/n Remove erlang_service synthetic include file tracking
Browse files Browse the repository at this point in the history
Summary:
We had a workaround where the erlang service compile step would tell us what files it had included, and we registered a read on them in salsa to track dependencies.

As we now process the include file resolution via ELP, this happens automatically, to the workaround can be removed.

Reviewed By: michalmuskala

Differential Revision: D60510555

fbshipit-source-id: 278793603d24c70e1ec25a02127df8d4c1707f9d
  • Loading branch information
alanz authored and facebook-github-bot committed Aug 1, 2024
1 parent 79fa273 commit 8e23199
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 59 deletions.
5 changes: 0 additions & 5 deletions crates/erlang_service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ impl Response {
pub struct ParseResult {
pub ast: Arc<Vec<u8>>,
pub stub: Arc<Vec<u8>>,
pub files: Arc<Vec<u8>>,
pub errors: Vec<ParseError>,
pub warnings: Vec<ParseError>,
}
Expand All @@ -256,7 +255,6 @@ impl ParseResult {
Self {
ast: Arc::default(),
stub: Arc::default(),
files: Arc::default(),
errors: vec![error],
warnings: Vec::default(),
}
Expand Down Expand Up @@ -377,7 +375,6 @@ impl Connection {
) -> Option<ParseResult> {
let mut ast = vec![];
let mut stub = vec![];
let mut files = vec![];
let mut warnings = vec![];
let mut errors = vec![];
let mut opens = vec![];
Expand All @@ -388,7 +385,6 @@ impl Connection {
match tag {
b"AST" => ast = data,
b"STU" => stub = data,
b"FIL" => files = data,
b"WAR" => warnings = data,
b"ERR" => errors = data,
b"OPN" => opens = data,
Expand All @@ -400,7 +396,6 @@ impl Connection {
Ok(ParseResult {
ast: Arc::new(ast),
stub: Arc::new(stub),
files: Arc::new(files),
warnings: decode_errors(&warnings).context("decoding warnings")?,
errors: decode_errors(&errors).context("decoding errors")?,
})
Expand Down
41 changes: 0 additions & 41 deletions crates/ide_db/src/erl_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use elp_base_db::FileId;
use elp_base_db::IncludeCtx;
use elp_base_db::ProjectId;
use elp_base_db::SourceDatabase;
use elp_base_db::VfsPath;
use elp_erlang_service::Format;
use elp_erlang_service::IncludeType;
use elp_erlang_service::ParseError;
Expand All @@ -30,7 +29,6 @@ use crate::erlang_service::ParseRequest;
use crate::metadata;
use crate::metadata::Metadata;
use crate::LineIndexDatabase;
use crate::RootDatabase;

pub trait AstLoader {
fn load_ast(
Expand Down Expand Up @@ -92,28 +90,6 @@ impl AstLoader for crate::RootDatabase {
|| self.unwind_if_cancelled(),
&move |include_type, path| resolve_include(self, file_id, include_type, &path),
);
let included_files = files_from_bytes(&r.files);
for file in included_files {
let file_path = PathBuf::from(file.clone());
let file = if file_path.is_absolute() {
file
} else {
match path.parent() {
None => file,
Some(file) => file
.to_path_buf()
.join(file)
.as_os_str()
.to_string_lossy()
.to_string(),
}
};
let file_path = VfsPath::new_real_path(file);
if let Some(file_id) = find_path_in_project(self, project_id, &file_path) {
// Dummy read of file revision to make DB track changes
let _ = self.file_revision(file_id);
}
}
r
}
}
Expand Down Expand Up @@ -191,20 +167,3 @@ fn elp_metadata(db: &dyn ErlAstDatabase, file_id: FileId) -> Metadata {
let source = db.parse(file_id);
metadata::collect_metadata(&line_index, &file_text, &source)
}

pub fn files_from_bytes(bytes: &[u8]) -> Vec<String> {
let str = String::from_utf8_lossy(bytes);
str.split('\n').map(|s| s.to_string()).collect::<Vec<_>>()
}

fn find_path_in_project(
db: &RootDatabase,
project_id: ProjectId,
path: &VfsPath,
) -> Option<FileId> {
let project = db.project_data(project_id);
project
.source_roots
.iter()
.find_map(|&source_root_id| db.source_root(source_root_id).file_for_path(path))
}
19 changes: 6 additions & 13 deletions erlang_service/src/erlang_service_lint.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,27 @@ run(Id, [FileName, Options0, OverrideOptions, PostProcess, Deterministic]) ->
end,
case lint_file(Forms3, FileName, Options3, OverrideOptions) of
{ok, []} ->
{Stub, AST, FILES} = partition_stub(Forms3),
{Stub, AST} = partition_stub(Forms3),
ResultStub = PostProcess(Stub, FileName),
ResultAST = PostProcess(AST, FileName),
ResultFILES = unicode:characters_to_binary(FILES),
{ok, [{<<"AST">>, ResultAST}, {<<"STU">>, ResultStub}, {<<"FIL">>, ResultFILES}]};
{ok, [{<<"AST">>, ResultAST}, {<<"STU">>, ResultStub}]};
{ok, Warnings} ->
{Stub, AST, FILES} = partition_stub(Forms3),
{Stub, AST} = partition_stub(Forms3),
ResultStub = PostProcess(Stub, FileName),
ResultAST = PostProcess(AST, FileName),
ResultFILES = unicode:characters_to_binary(FILES),
FormattedWarnings = format_errors(Forms3, FileName, Warnings),
{ok, [{<<"AST">>, ResultAST},
{<<"STU">>, ResultStub},
{<<"FIL">>, ResultFILES},
{<<"WAR">>, FormattedWarnings}]};
{error, Errors, Warnings} ->
{Stub, AST, FILES} = partition_stub(Forms3),
{Stub, AST} = partition_stub(Forms3),
ResultStub = PostProcess(Stub, FileName),
ResultAST = PostProcess(AST, FileName),
ResultFILES = unicode:characters_to_binary(FILES),
FormattedErrors = format_errors(Forms3, FileName, Errors),
FormattedWarnings = format_errors(Forms3, FileName, Warnings),
{ok, [
{<<"AST">>, ResultAST},
{<<"STU">>, ResultStub},
{<<"FIL">>, ResultFILES},
{<<"ERR">>, FormattedErrors},
{<<"WAR">>, FormattedWarnings}
]}
Expand Down Expand Up @@ -160,11 +155,9 @@ vararg_transform(Atomic) ->
Atomic.

-spec partition_stub([elp_parse:abstract_form()]) ->
{Stub :: [elp_parse:abstract_form()], AST :: [elp_parse:abstract_form()], FILES :: string()}.
{Stub :: [elp_parse:abstract_form()], AST :: [elp_parse:abstract_form()]}.
partition_stub(Forms) -> {[Attr || {attribute, _, _, _} = Attr <- Forms],
Forms,
% eqwalizer:ignore - We know that the Name is a string, from matching the abstract form
string:join([Name || {attribute, _, file, {Name,_}} = _Attr <- Forms],"\n")}.
Forms}.


format_errors(Forms, OriginalPath, Warnings) ->
Expand Down

0 comments on commit 8e23199

Please sign in to comment.