Skip to content

Commit 9640163

Browse files
committed
Merge remote-tracking branch 'origin/main' into merge
2 parents e45282d + 8a629f2 commit 9640163

File tree

118 files changed

+3894
-3028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3894
-3028
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20-
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu, platform: linux-x64, cross: general }
21-
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu, platform: linux-x64, cross: zigbuild, glibc: 2.17 }
22-
- { os: ubuntu-22.04, target: aarch64-unknown-linux-gnu, platform: linux-arm64, cross: zigbuild, glibc: 2.17 }
23-
- { os: ubuntu-22.04, target: riscv64gc-unknown-linux-gnu, platform: linux-riscv64,cross: cross }
24-
- { os: ubuntu-22.04, target: x86_64-unknown-linux-musl, platform: linux-musl, cross: cross }
25-
- { os: macos-latest, target: x86_64-apple-darwin, platform: darwin-x64, cross: general-macos-intel }
26-
- { os: macos-latest, target: aarch64-apple-darwin, platform: darwin-arm64, cross: general }
27-
- { os: windows-latest, target: x86_64-pc-windows-msvc, platform: win32-x64, cross: general }
28-
- { os: windows-latest, target: i686-pc-windows-msvc, platform: win32-ia32, cross: general }
29-
- { os: windows-latest, target: aarch64-pc-windows-msvc, platform: win32-arm64, cross: general }
20+
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu, platform: linux-x64, cross: general, crate: emmylua_ls }
21+
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu, platform: linux-x64, cross: zigbuild, crate: emmylua_ls, glibc: 2.17 }
22+
- { os: ubuntu-22.04, target: aarch64-unknown-linux-gnu, platform: linux-arm64, cross: zigbuild, crate: emmylua_ls, glibc: 2.17 }
23+
- { os: ubuntu-22.04, target: riscv64gc-unknown-linux-gnu, platform: linux-riscv64,cross: cross, crate: emmylua_ls }
24+
- { os: ubuntu-22.04, target: x86_64-unknown-linux-musl, platform: linux-musl, cross: cross, crate: emmylua_ls }
25+
- { os: macos-latest, target: x86_64-apple-darwin, platform: darwin-x64, cross: general-macos-intel, crate: emmylua_ls }
26+
- { os: macos-latest, target: aarch64-apple-darwin, platform: darwin-arm64, cross: general, crate: emmylua_ls }
27+
- { os: windows-latest, target: x86_64-pc-windows-msvc, platform: win32-x64, cross: general, crate: emmylua_ls }
28+
- { os: windows-latest, target: i686-pc-windows-msvc, platform: win32-ia32, cross: general, crate: emmylua_ls }
29+
- { os: windows-latest, target: aarch64-pc-windows-msvc, platform: win32-arm64, cross: general, crate: emmylua_ls }
30+
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu, platform: linux-x64, cross: general, crate: emmylua_check }
31+
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu, platform: linux-x64, cross: general, crate: emmylua_doc_cli }
3032
runs-on: ${{ matrix.os }}
3133
steps:
3234
- uses: actions/checkout@v4
@@ -43,47 +45,46 @@ jobs:
4345
if: ${{ matrix.cross == 'general' }}
4446
run: |
4547
rustup target add ${{ matrix.target }}
46-
cargo build --release --target ${{ matrix.target }} -p emmylua_ls
48+
cargo build --release --target ${{ matrix.target }} -p ${{ matrix.crate }}
4749
- name: Build - cross
4850
if: ${{ matrix.cross == 'cross' }}
4951
run: |
5052
cargo install cross
51-
cross build --release --target ${{ matrix.target }} -p emmylua_ls
53+
cross build --release --target ${{ matrix.target }} -p ${{ matrix.crate }}
5254
- name: Build -zigbuild
5355
if: ${{ matrix.cross == 'zigbuild' }}
5456
run: |
5557
rustup target add ${{ matrix.target }}
5658
cargo install --locked cargo-zigbuild
5759
pip3 install ziglang
58-
cargo zigbuild --release --target ${{ matrix.target }}.${{ matrix.glibc }} -p emmylua_ls
60+
cargo zigbuild --release --target ${{ matrix.target }}.${{ matrix.glibc }} -p ${{ matrix.crate }}
5961
- name: Build - general macos-intel
6062
if: ${{ matrix.cross == 'general-macos-intel' }}
6163
run: |
6264
rustup target add ${{ matrix.target }}
63-
cargo build --release --target ${{ matrix.target }} -p emmylua_ls
64-
otool -l ./target/${{ matrix.target }}/release/emmylua_ls | grep -A4 "LC_BUILD_VERSION\|LC_VERSION_MIN_MACOSX"
65+
cargo build --release --target ${{ matrix.target }} -p ${{ matrix.crate }}
6566
- name: copy-binary
6667
if: ${{ matrix.os != 'windows-latest' }}
6768
run: |
6869
mkdir -p ${{ github.workspace }}/artifact/
69-
cp ${{ github.workspace }}/target/${{ matrix.target }}/release/emmylua_ls ${{ github.workspace }}/artifact/
70+
cp ${{ github.workspace }}/target/${{ matrix.target }}/release/${{ matrix.crate }} ${{ github.workspace }}/artifact/
7071
- name: copy-binary-windows
7172
if: ${{ matrix.os == 'windows-latest' }}
7273
run: |
7374
mkdir -p ${{ github.workspace }}/artifact/
74-
cp ${{ github.workspace }}/target/${{ matrix.target }}/release/emmylua_ls.exe ${{ github.workspace }}/artifact/
75+
cp ${{ github.workspace }}/target/${{ matrix.target }}/release/${{ matrix.crate }}.exe ${{ github.workspace }}/artifact/
7576
shell: pwsh
7677
- name: Upload
7778
if: ${{ matrix.cross != 'zigbuild' }}
7879
uses: actions/upload-artifact@v4
7980
with:
80-
name: emmylua_ls-${{ matrix.platform }}
81+
name: ${{ matrix.crate }}-${{ matrix.platform }}
8182
path: ${{ github.workspace }}/artifact/
8283
- name: Upload zigbuild
8384
if: ${{ matrix.cross == 'zigbuild' }}
8485
uses: actions/upload-artifact@v4
8586
with:
86-
name: emmylua_ls-${{ matrix.platform }}-glibc.${{ matrix.glibc }}
87+
name: ${{ matrix.crate }}-${{ matrix.platform }}-glibc.${{ matrix.glibc }}
8788
path: ${{ github.workspace }}/artifact/
8889
release:
8990
needs: build
@@ -101,6 +102,8 @@ jobs:
101102
chmod +x emmylua_ls-linux-riscv64/emmylua_ls
102103
chmod +x emmylua_ls-darwin-x64/emmylua_ls
103104
chmod +x emmylua_ls-darwin-arm64/emmylua_ls
105+
chmod +x emmylua_check-linux-x64/emmylua_check
106+
chmod +x emmylua_doc_cli-linux-x64-glibc.2.17/emmylua_doc_cli
104107
105108
tar -zcvf emmylua_ls-linux-x64.tar.gz -C emmylua_ls-linux-x64 emmylua_ls
106109
tar -zcvf emmylua_ls-linux-x64-glibc.2.17.tar.gz -C emmylua_ls-linux-x64-glibc.2.17 emmylua_ls
@@ -109,6 +112,8 @@ jobs:
109112
tar -zcvf emmylua_ls-linux-riscv64.tar.gz -C emmylua_ls-linux-riscv64 emmylua_ls
110113
tar -zcvf emmylua_ls-darwin-x64.tar.gz -C emmylua_ls-darwin-x64 emmylua_ls
111114
tar -zcvf emmylua_ls-darwin-arm64.tar.gz -C emmylua_ls-darwin-arm64 emmylua_ls
115+
tar -zcvf emmylua_check-linux-x64.tar.gz -C emmylua_check-linux-x64 emmylua_check
116+
tar -zcvf emmylua_doc_cli-linux-x64.tar.gz -C emmylua_doc_cli-linux-x64 emmylua_doc_cli
112117
- name: windows compress
113118
run: |
114119
cd emmylua_ls-win32-x64
@@ -134,4 +139,6 @@ jobs:
134139
emmylua_ls-linux-riscv64.tar.gz
135140
emmylua_ls-darwin-x64.tar.gz
136141
emmylua_ls-darwin-arm64.tar.gz
142+
emmylua_check-linux-x64.tar.gz
143+
emmylua_doc_cli-linux-x64.tar.gz
137144
token: ${{ secrets.RELEASE }}

crates/emmylua_check/Cargo.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@ log.workspace = true
2323
fern.workspace = true
2424
rowan.workspace = true
2525
walkdir.workspace = true
26-
tokio.workspace = true
2726
tokio-util.workspace = true
28-
clap.workspace = true
2927
ansi_term.workspace = true
28+
tokio.workspace = true
29+
30+
[dependencies.clap]
31+
workspace = true
32+
optional = true
33+
34+
[[bin]]
35+
name = "emmylua_check"
36+
required-features = ["cli"]
37+
38+
[features]
39+
default = ["cli"]
40+
cli = ["dep:clap"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use clap::Parser;
2+
use emmylua_check::{cmd_args::CmdArgs, run_check};
3+
use std::error::Error;
4+
5+
#[tokio::main]
6+
async fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
7+
let cmd_args = CmdArgs::parse();
8+
run_check(cmd_args).await
9+
}

crates/emmylua_check/src/cmd_args.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
1+
#[cfg(feature = "cli")]
12
use clap::{Parser, ValueEnum};
3+
24
use std::path::PathBuf;
35

46
#[allow(unused)]
5-
#[derive(Debug, Parser, Clone)]
7+
#[derive(Debug, Clone)]
8+
#[cfg_attr(feature = "cli", derive(Parser))]
69
pub struct CmdArgs {
710
/// Configuration file paths.
811
/// If not provided, both ".emmyrc.json" and ".luarc.json" will be searched in the workspace
912
/// directory
10-
#[arg(short, long, value_delimiter = ',')]
13+
#[cfg_attr(feature = "cli", arg(short, long, value_delimiter = ','))]
1114
pub config: Option<Vec<PathBuf>>,
1215

1316
/// Path to the workspace directory
1417
pub workspace: PathBuf,
1518

1619
/// Comma separated list of ignore patterns.
1720
/// Patterns must follow glob syntax
18-
#[arg(short, long, value_delimiter = ',')]
21+
#[cfg_attr(feature = "cli", arg(short, long, value_delimiter = ','))]
1922
pub ignore: Option<Vec<String>>,
2023

2124
/// Specify output format
22-
#[arg(long, default_value = "text", value_enum, ignore_case = true)]
25+
#[cfg_attr(
26+
feature = "cli",
27+
arg(long, default_value = "text", value_enum, ignore_case = true)
28+
)]
2329
pub output_format: OutputFormat,
2430

2531
/// Specify output destination (stdout or a file path, only used when output_format is json).
26-
#[arg(long, default_value = "stdout")]
32+
#[cfg_attr(feature = "cli", arg(long, default_value = "stdout"))]
2733
pub output: OutputDestination,
2834

2935
/// Treat warnings as errors
30-
#[arg(long)]
36+
#[cfg_attr(feature = "cli", arg(long))]
3137
pub warnings_as_errors: bool,
3238

3339
/// Verbose output
34-
#[arg(long)]
40+
#[cfg_attr(feature = "cli", arg(long))]
3541
pub verbose: bool,
3642
}
3743

38-
#[derive(Debug, Clone, PartialEq, ValueEnum)]
44+
#[derive(Debug, Clone, PartialEq)]
45+
#[cfg_attr(feature = "cli", derive(ValueEnum))]
3946
pub enum OutputFormat {
4047
Json,
4148
Text,

crates/emmylua_check/src/init.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::{path::PathBuf, str::FromStr, sync::Arc};
22

33
use emmylua_code_analysis::{
4-
load_configs, load_workspace_files, update_code_style, EmmyLuaAnalysis, Emmyrc, LuaFileInfo,
4+
load_configs, load_workspace_files, update_code_style, DbIndex, EmmyLuaAnalysis, Emmyrc,
5+
FileId, LuaFileInfo,
56
};
67

78
fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf {
@@ -174,3 +175,15 @@ pub fn calculate_include_and_exclude(
174175

175176
(include, exclude, exclude_dirs)
176177
}
178+
179+
pub fn get_need_check_ids(db: &DbIndex, files: Vec<FileId>, workspace: &PathBuf) -> Vec<FileId> {
180+
let mut need_check_files = Vec::new();
181+
for file_id in files {
182+
let file_path = db.get_vfs().get_file_path(&file_id).unwrap();
183+
if file_path.starts_with(workspace) {
184+
need_check_files.push(file_id);
185+
}
186+
}
187+
188+
need_check_files
189+
}
Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
mod cmd_args;
1+
pub mod cmd_args;
22
mod init;
33
mod output;
44
mod terminal_display;
55

6-
use clap::Parser;
7-
use cmd_args::CmdArgs;
8-
use emmylua_code_analysis::{DbIndex, FileId};
6+
pub use cmd_args::*;
97
use fern::Dispatch;
108
use log::LevelFilter;
119
use output::output_result;
12-
use std::{error::Error, path::PathBuf, sync::Arc};
10+
use std::{error::Error, sync::Arc};
1311
use tokio_util::sync::CancellationToken;
1412

15-
#[tokio::main]
16-
async fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
17-
let cmd_args = CmdArgs::parse();
13+
use crate::init::get_need_check_ids;
14+
15+
pub async fn run_check(cmd_args: CmdArgs) -> Result<(), Box<dyn Error + Sync + Send>> {
1816
let mut workspace = cmd_args.workspace;
1917
if !workspace.is_absolute() {
2018
workspace = std::env::current_dir()?.join(workspace);
@@ -54,7 +52,6 @@ async fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
5452
let analysis = match init::load_workspace(workspace.clone(), cmd_args.config, cmd_args.ignore) {
5553
Some(analysis) => analysis,
5654
None => {
57-
eprintln!("Failed to load workspace");
5855
return Err("Failed to load workspace".into());
5956
}
6057
};
@@ -94,15 +91,3 @@ async fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
9491
eprintln!("Check finished");
9592
Ok(())
9693
}
97-
98-
fn get_need_check_ids(db: &DbIndex, files: Vec<FileId>, workspace: &PathBuf) -> Vec<FileId> {
99-
let mut need_check_files = Vec::new();
100-
for file_id in files {
101-
let file_path = db.get_vfs().get_file_path(&file_id).unwrap();
102-
if file_path.starts_with(workspace) {
103-
need_check_files.push(file_id);
104-
}
105-
}
106-
107-
need_check_files
108-
}

crates/emmylua_code_analysis/src/compilation/analyzer/doc/infer_type.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,23 +331,23 @@ fn infer_binary_type(analyzer: &mut DocAnalyzer, binary_type: &LuaDocBinaryType)
331331
match op.get_op() {
332332
LuaTypeBinaryOperator::Union => match (left_type, right_type) {
333333
(LuaType::Union(left_type_union), LuaType::Union(right_type_union)) => {
334-
let mut left_types = left_type_union.into_types();
335-
let right_types = right_type_union.into_types();
336-
left_types.extend(right_types);
337-
return LuaType::Union(LuaUnionType::new(left_types).into());
334+
let mut left_type_set = left_type_union.into_vec();
335+
let right_types = right_type_union.into_vec();
336+
left_type_set.extend(right_types);
337+
return LuaType::Union(LuaUnionType::from_vec(left_type_set).into());
338338
}
339339
(LuaType::Union(left_type_union), right) => {
340-
let mut left_types = (*left_type_union).into_types();
340+
let mut left_types = (*left_type_union).into_vec();
341341
left_types.push(right);
342-
return LuaType::Union(LuaUnionType::new(left_types).into());
342+
return LuaType::Union(LuaUnionType::from_vec(left_types).into());
343343
}
344344
(left, LuaType::Union(right_type_union)) => {
345-
let mut right_types = (*right_type_union).into_types();
345+
let mut right_types = (*right_type_union).into_vec();
346346
right_types.push(left);
347-
return LuaType::Union(LuaUnionType::new(right_types).into());
347+
return LuaType::Union(LuaUnionType::from_vec(right_types).into());
348348
}
349349
(left, right) => {
350-
return LuaType::Union(LuaUnionType::new(vec![left, right]).into());
350+
return LuaType::Union(LuaUnionType::from_vec(vec![left, right]).into());
351351
}
352352
},
353353
LuaTypeBinaryOperator::Intersection => match (left_type, right_type) {

0 commit comments

Comments
 (0)