Skip to content

Commit

Permalink
Do not report OTP diagnostics by default
Browse files Browse the repository at this point in the history
Summary:
* Add a function to verify whether a file id belongs to OTP
* Only return OTP diagnostics if the server is configured to do so (disabled for now, configurable later in the stack)

Reviewed By: alanz

Differential Revision: D56353250

fbshipit-source-id: 07f7713793dbdcfa4edcbb9221e3e4e68d820ede
  • Loading branch information
robertoaloi authored and facebook-github-bot committed Apr 22, 2024
1 parent c97d4ab commit 28a3fcd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
9 changes: 9 additions & 0 deletions crates/base_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub trait SourceDatabase: FileLoader + salsa::Database {

fn is_generated(&self, file_id: FileId) -> bool;

fn is_otp(&self, file_id: FileId) -> Option<bool>;

fn is_test_suite_or_test_helper(&self, file_id: FileId) -> Option<bool>;

fn file_app_type(&self, file_id: FileId) -> Option<AppType>;
Expand Down Expand Up @@ -216,6 +218,13 @@ fn is_generated(db: &dyn SourceDatabase, file_id: FileId) -> bool {
contents[0..(2001.min(contents.len()))].contains(&format!("{}generated", "@"))
}

fn is_otp(db: &dyn SourceDatabase, file_id: FileId) -> Option<bool> {
let root_id = db.file_source_root(file_id);
let app_data = db.app_data(root_id)?;
let project_id = app_data.project_id;
Some(db.project_data(project_id).otp_project_id == Some(project_id))
}

fn is_test_suite_or_test_helper(db: &dyn SourceDatabase, file_id: FileId) -> Option<bool> {
// Context for T171541590
let _ = stdx::panic_context::enter(format!("\nis_test_suite_or_test_helper: {:?}", file_id));
Expand Down
42 changes: 34 additions & 8 deletions crates/elp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod progress;
pub mod setup;

const LOGGER_NAME: &str = "lsp";
const PARSE_SERVER_SUPPORTED_EXTENSIONS: &[FileKind] = &[
const ERLANG_SERVICE_SUPPORTED_EXTENSIONS: &[FileKind] = &[
FileKind::SrcModule,
FileKind::TestModule,
FileKind::Header,
Expand Down Expand Up @@ -231,6 +231,7 @@ pub struct Server {
ai_completion: Arc<Mutex<AiCompletion>>,
include_generated: bool,
compile_options: Vec<CompileOption>,
report_otp_diagnostics: bool,

// Progress reporting
vfs_config_version: u32,
Expand Down Expand Up @@ -282,6 +283,7 @@ impl Server {
vfs_config_version: 0,
include_generated: true,
compile_options: vec![],
report_otp_diagnostics: false,
};

// Run config-based initialisation
Expand Down Expand Up @@ -874,8 +876,12 @@ impl Server {
let opened_documents = self.opened_documents();
let snapshot = self.snapshot();

let supported_opened_documents: Vec<FileId> = opened_documents
.into_iter()
.filter(|file_id| self.report_otp_diagnostics || !is_otp(&snapshot.analysis, *file_id))
.collect();
self.task_pool.handle.spawn(move || {
let diagnostics = opened_documents
let diagnostics = supported_opened_documents
.into_iter()
.filter_map(|file_id| Some((file_id, snapshot.native_diagnostics(file_id)?)))
.collect();
Expand All @@ -902,8 +908,12 @@ impl Server {

let spinner = self.progress.begin_spinner("EqWAlizing".to_string());

let supported_opened_documents: Vec<FileId> = opened_documents
.into_iter()
.filter(|file_id| self.report_otp_diagnostics || !is_otp(&snapshot.analysis, *file_id))
.collect();
self.task_pool.handle.spawn(move || {
let diagnostics = opened_documents
let diagnostics = supported_opened_documents
.into_iter()
.filter_map(|file_id| Some((file_id, snapshot.eqwalizer_diagnostics(file_id)?)))
.collect();
Expand Down Expand Up @@ -962,7 +972,10 @@ impl Server {

let supported_opened_documents: Vec<FileId> = opened_documents
.into_iter()
.filter(|file_id| is_supported_by_edoc(&snapshot.analysis, *file_id))
.filter(|file_id| {
(self.report_otp_diagnostics || !is_otp(&snapshot.analysis, *file_id))
&& is_supported_by_edoc(&snapshot.analysis, *file_id)
})
.collect();
self.task_pool.handle.spawn(move || {
let diagnostics = supported_opened_documents
Expand All @@ -989,7 +1002,10 @@ impl Server {

let supported_opened_documents: Vec<FileId> = opened_documents
.into_iter()
.filter(|file_id| is_supported_by_ct(&snapshot.analysis, *file_id))
.filter(|file_id| {
(self.report_otp_diagnostics || !is_otp(&snapshot.analysis, *file_id))
&& is_supported_by_ct(&snapshot.analysis, *file_id)
})
.collect();
let config = DiagnosticsConfig::default();
self.task_pool.handle.spawn(move || {
Expand Down Expand Up @@ -1043,7 +1059,10 @@ impl Server {
let snapshot = self.snapshot();
let supported_opened_documents: Vec<FileId> = opened_documents
.into_iter()
.filter(|file_id| is_supported_by_parse_server(&snapshot.analysis, *file_id))
.filter(|file_id| {
(self.report_otp_diagnostics || !is_otp(&snapshot.analysis, *file_id))
&& is_supported_by_erlang_service(&snapshot.analysis, *file_id)
})
.collect();
let diagnostics_config = DiagnosticsConfig::default()
.set_include_generated(self.include_generated)
Expand Down Expand Up @@ -1642,9 +1661,16 @@ pub fn file_id_to_url(vfs: &Vfs, id: FileId) -> Url {
convert::url_from_abs_path(path)
}

pub fn is_supported_by_parse_server(analysis: &Analysis, id: FileId) -> bool {
pub fn is_otp(analysis: &Analysis, id: FileId) -> bool {
match analysis.is_otp(id) {
Ok(is_otp) => Some(true) == is_otp,
Err(_) => false,
}
}

pub fn is_supported_by_erlang_service(analysis: &Analysis, id: FileId) -> bool {
match analysis.file_kind(id) {
Ok(kind) => PARSE_SERVER_SUPPORTED_EXTENSIONS.contains(&kind),
Ok(kind) => ERLANG_SERVICE_SUPPORTED_EXTENSIONS.contains(&kind),
Err(_) => false,
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ impl Analysis {
self.with_db(|db| db.is_test_suite_or_test_helper(file_id))
}

pub fn is_otp(&self, file_id: FileId) -> Cancellable<Option<bool>> {
self.with_db(|db| db.is_otp(file_id))
}

/// Search symbols. Only module names are currently supported.
pub fn symbol_search(
&self,
Expand Down

0 comments on commit 28a3fcd

Please sign in to comment.