Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly filter clippy results to include the current file only #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion samples/file.rs

This file was deleted.

1 change: 1 addition & 0 deletions samples/rust-sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions samples/rust-sample/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions samples/rust-sample/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "rust-sample"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
6 changes: 6 additions & 0 deletions samples/rust-sample/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod other_file;

fn main() {
println!("Hello, {}!", "world");
other_file::do_thing();
}
3 changes: 3 additions & 0 deletions samples/rust-sample/src/other_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn do_thing() {
println!("Hello, {}!", "world");
}
17 changes: 7 additions & 10 deletions src/linters/cargo-clippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import { debug } from "../helpers/debug";
type ClippyEntry = {
reason: string;
message: ClippyMessage;
target?: {
src_path: string;
};
};

type ClippyMessageChildren = {
Expand All @@ -42,6 +39,7 @@ type ClippySpan = {
column_end: number;
line_start: number;
line_end: number;
file_name: string;
suggested_replacement?: string;
};

Expand Down Expand Up @@ -69,8 +67,6 @@ export const getOffenses: LinterGetOffensesFunction = ({ stdout, uri }) => {
const offenses: LinterOffense[] = [];

entries.forEach((entry: ClippyEntry) => {
const src = "file://" + (entry.target?.src_path ?? "");

if (entry.reason !== "compiler-message") {
debug("unexpected reason:", entry.reason);
return;
Expand All @@ -81,11 +77,6 @@ export const getOffenses: LinterGetOffensesFunction = ({ stdout, uri }) => {
return;
}

if (src !== uri.toString()) {
debug("offense is for another file", { src, uri: uri.toString() });
return;
}

const help = entry.message.children?.find(
(child) =>
child.level === "help" &&
Expand All @@ -104,8 +95,14 @@ export const getOffenses: LinterGetOffensesFunction = ({ stdout, uri }) => {
line_end: lineEnd,
column_start: columnStart,
column_end: columnEnd,
file_name: fileName,
} = span;

if (!uri.toString().endsWith(span.file_name.replace('\\', "/"))) {
debug("span is for another file", { span_file_name: span.file_name, current_document: uri.toString() });
return;
}

let replacement = "";

const range = {
Expand Down