Skip to content

Commit 294a787

Browse files
committed
library will no longer use the ignore configuration.
1 parent 9d4f8c6 commit 294a787

File tree

4 files changed

+53
-36
lines changed

4 files changed

+53
-36
lines changed

crates/emmylua_check/src/init.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn setup_logger(verbose: bool) {
6060

6161
pub fn load_workspace(
6262
main_path: PathBuf,
63-
mut workspace_folders: Vec<PathBuf>,
63+
workspace_folders: Vec<PathBuf>,
6464
config_paths: Option<Vec<PathBuf>>,
6565
ignore: Option<Vec<String>>,
6666
) -> Option<EmmyLuaAnalysis> {
@@ -93,9 +93,10 @@ pub fn load_workspace(
9393
let mut analysis = EmmyLuaAnalysis::new();
9494
analysis.update_config(emmyrc.clone().into());
9595
analysis.init_std_lib(None);
96-
96+
let mut workspace_infos = vec![];
9797
for path in &workspace_folders {
9898
analysis.add_main_workspace(path.clone());
99+
workspace_infos.push((path.clone(), false));
99100
}
100101

101102
for root in &emmyrc.workspace.workspace_roots {
@@ -104,10 +105,10 @@ pub fn load_workspace(
104105

105106
for lib in &emmyrc.workspace.library {
106107
analysis.add_library_workspace(PathBuf::from(lib));
107-
workspace_folders.push(PathBuf::from(lib));
108+
workspace_infos.push((PathBuf::from(lib), true));
108109
}
109110

110-
let file_infos = collect_files(&workspace_folders, &analysis.emmyrc, ignore);
111+
let file_infos = collect_files(&workspace_infos, &analysis.emmyrc, ignore);
111112
let files = file_infos
112113
.into_iter()
113114
.filter_map(|file| {
@@ -134,7 +135,7 @@ pub fn load_workspace(
134135
}
135136

136137
pub fn collect_files(
137-
workspaces: &Vec<PathBuf>,
138+
workspaces: &Vec<(PathBuf, bool)>,
138139
emmyrc: &Emmyrc,
139140
ignore: Option<Vec<String>>,
140141
) -> Vec<LuaFileInfo> {
@@ -143,15 +144,19 @@ pub fn collect_files(
143144

144145
let encoding = &emmyrc.workspace.encoding;
145146

146-
for workspace in workspaces {
147-
let loaded = load_workspace_files(
148-
workspace,
149-
&match_pattern,
150-
&exclude,
151-
&exclude_dir,
152-
Some(encoding),
153-
)
154-
.ok();
147+
for (workspace, is_lib) in workspaces {
148+
let loaded = if *is_lib {
149+
load_workspace_files(workspace, &match_pattern, &[], &[], Some(encoding)).ok()
150+
} else {
151+
load_workspace_files(
152+
workspace,
153+
&match_pattern,
154+
&exclude,
155+
&exclude_dir,
156+
Some(encoding),
157+
)
158+
.ok()
159+
};
155160
if let Some(loaded) = loaded {
156161
files.extend(loaded);
157162
}

crates/emmylua_ls/src/context/workspace_manager.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,23 @@ pub enum WorkspaceImport {
2424
pub struct WorkspaceFolder {
2525
pub root: PathBuf,
2626
pub import: WorkspaceImport,
27+
pub is_library: bool,
2728
}
2829

2930
impl WorkspaceFolder {
30-
pub fn new(root: PathBuf) -> Self {
31+
pub fn new(root: PathBuf, is_library: bool) -> Self {
3132
Self {
3233
root,
3334
import: WorkspaceImport::All,
35+
is_library,
3436
}
3537
}
3638

37-
pub fn with_sub_paths(root: PathBuf, sub_paths: Vec<PathBuf>) -> Self {
39+
pub fn with_sub_paths(root: PathBuf, sub_paths: Vec<PathBuf>, is_library: bool) -> Self {
3840
Self {
3941
root,
4042
import: WorkspaceImport::SubPaths(sub_paths),
43+
is_library,
4144
}
4245
}
4346
}

crates/emmylua_ls/src/handlers/initialized/collect_files.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,38 @@ pub fn collect_files(workspaces: &Vec<WorkspaceFolder>, emmyrc: &Emmyrc) -> Vec<
1818
for workspace in workspaces {
1919
match &workspace.import {
2020
WorkspaceImport::All => {
21-
let loaded = load_workspace_files(
22-
&workspace.root,
23-
&match_pattern,
24-
&exclude,
25-
&exclude_dir,
26-
Some(encoding),
27-
)
28-
.ok();
21+
let loaded = if workspace.is_library {
22+
load_workspace_files(&workspace.root, &match_pattern, &[], &[], Some(encoding))
23+
.ok()
24+
} else {
25+
load_workspace_files(
26+
&workspace.root,
27+
&match_pattern,
28+
&exclude,
29+
&exclude_dir,
30+
Some(encoding),
31+
)
32+
.ok()
33+
};
2934
if let Some(loaded) = loaded {
3035
files.extend(loaded);
3136
}
3237
}
3338
WorkspaceImport::SubPaths(paths) => {
3439
for sub in paths {
3540
let target = workspace.root.join(sub);
36-
let loaded = load_workspace_files(
37-
&target,
38-
&match_pattern,
39-
&exclude,
40-
&exclude_dir,
41-
Some(encoding),
42-
)
43-
.ok();
41+
let loaded = if workspace.is_library {
42+
load_workspace_files(&target, &match_pattern, &[], &[], Some(encoding)).ok()
43+
} else {
44+
load_workspace_files(
45+
&target,
46+
&match_pattern,
47+
&exclude,
48+
&exclude_dir,
49+
Some(encoding),
50+
)
51+
.ok()
52+
};
4453
if let Some(loaded) = loaded {
4554
files.extend(loaded);
4655
}

crates/emmylua_ls/src/handlers/initialized/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ pub async fn init_analysis(
136136
log::info!("add workspace root: {:?}", workspace_root);
137137
let root_path = PathBuf::from(workspace_root);
138138
mut_analysis.add_main_workspace(root_path.clone());
139-
workspace_folders.push(WorkspaceFolder::new(root_path));
140139
}
141140

142141
for lib in &emmyrc.workspace.library {
143142
log::info!("add library: {:?}", lib);
144143
let lib_path = PathBuf::from(lib);
145144
mut_analysis.add_library_workspace(lib_path.clone());
146-
workspace_folders.push(WorkspaceFolder::new(lib_path));
145+
workspace_folders.push(WorkspaceFolder::new(lib_path, true));
147146
}
148147

149148
for package_dir in &emmyrc.workspace.package_dirs {
@@ -160,6 +159,7 @@ pub async fn init_analysis(
160159
workspace_folders.push(WorkspaceFolder::with_sub_paths(
161160
parent_path,
162161
vec![PathBuf::from(name)],
162+
true,
163163
));
164164
} else {
165165
log::warn!("package dir {:?} has no file name", package_path);
@@ -214,7 +214,7 @@ pub fn get_workspace_folders(params: &InitializeParams) -> Vec<WorkspaceFolder>
214214
if let Some(workspaces) = &params.workspace_folders {
215215
for workspace in workspaces {
216216
if let Some(path) = uri_to_file_path(&workspace.uri) {
217-
workspace_folders.push(WorkspaceFolder::new(path));
217+
workspace_folders.push(WorkspaceFolder::new(path, false));
218218
}
219219
}
220220
}
@@ -225,7 +225,7 @@ pub fn get_workspace_folders(params: &InitializeParams) -> Vec<WorkspaceFolder>
225225
if let Some(uri) = &params.root_uri {
226226
let root_workspace = uri_to_file_path(uri);
227227
if let Some(path) = root_workspace {
228-
workspace_folders.push(WorkspaceFolder::new(path));
228+
workspace_folders.push(WorkspaceFolder::new(path, false));
229229
}
230230
}
231231
}

0 commit comments

Comments
 (0)