mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:31:48 +00:00
syntax-highlighter: add cargo clippy to bazel builds and fix warnings (#58096)
Co-authored-by: Jean-Hadrien Chabran <jean-hadrien.chabran@sourcegraph.com>
This commit is contained in:
parent
8a72da5a96
commit
75cc2d1141
4
.bazelrc
4
.bazelrc
@ -47,3 +47,7 @@ test:go-verbose-test --test_env=GO_TEST_WRAP_TESTV=1
|
||||
# .aspect/bazelrc/correctness.bazelrc sets this, but this breaks with a lot of Go external deps, so
|
||||
# we instead disable it.
|
||||
common --noincompatible_disallow_empty_glob
|
||||
|
||||
# Ensure clippy runs for rust targets
|
||||
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
|
||||
build --output_groups=+clippy_checks
|
||||
|
||||
@ -23,6 +23,7 @@ go_binary(
|
||||
go_cross_binary(
|
||||
name = "clear-darwin-arm64",
|
||||
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
|
||||
tags = ["manual"],
|
||||
target = ":clear",
|
||||
visibility = ["//testing:__pkg__"],
|
||||
)
|
||||
|
||||
@ -23,6 +23,7 @@ go_binary(
|
||||
go_cross_binary(
|
||||
name = "clone-and-index-darwin-arm64",
|
||||
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
|
||||
tags = ["manual"],
|
||||
target = ":clone-and-index",
|
||||
visibility = ["//testing:__pkg__"],
|
||||
)
|
||||
|
||||
@ -24,6 +24,7 @@ go_binary(
|
||||
go_cross_binary(
|
||||
name = "download-darwin-arm64",
|
||||
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
|
||||
tags = ["manual"],
|
||||
target = ":download",
|
||||
visibility = ["//testing:__pkg__"],
|
||||
)
|
||||
|
||||
@ -30,6 +30,7 @@ go_binary(
|
||||
go_cross_binary(
|
||||
name = "query-darwin-arm64",
|
||||
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
|
||||
tags = ["manual"],
|
||||
target = ":query",
|
||||
visibility = ["//testing:__pkg__"],
|
||||
)
|
||||
|
||||
@ -23,6 +23,7 @@ go_binary(
|
||||
go_cross_binary(
|
||||
name = "upload-gcs-darwin-arm64",
|
||||
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
|
||||
tags = ["manual"],
|
||||
target = ":upload-gcs",
|
||||
visibility = ["//testing:__pkg__"],
|
||||
)
|
||||
|
||||
@ -24,6 +24,7 @@ go_binary(
|
||||
go_cross_binary(
|
||||
name = "upload-darwin-arm64",
|
||||
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
|
||||
tags = ["manual"],
|
||||
target = ":upload",
|
||||
visibility = ["//testing:__pkg__"],
|
||||
)
|
||||
|
||||
@ -195,7 +195,7 @@ impl<'a> Scope<'a> {
|
||||
}
|
||||
ReassignmentBehavior::OldestIsDefinition => {
|
||||
if let Some(above) = declarations_above
|
||||
.into_iter()
|
||||
.iter_mut()
|
||||
.rev()
|
||||
.find(|x| x.contains_key(lvalue.identifier))
|
||||
{
|
||||
@ -540,9 +540,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_can_do_go() -> Result<()> {
|
||||
let mut config = crate::languages::get_local_configuration(BundledParser::Go).unwrap();
|
||||
let config = crate::languages::get_local_configuration(BundledParser::Go).unwrap();
|
||||
let source_code = include_str!("../testdata/locals.go");
|
||||
let doc = parse_file_for_lang(&mut config, source_code)?;
|
||||
let doc = parse_file_for_lang(config, source_code)?;
|
||||
|
||||
let dumped = snapshot_syntax_document(&doc, source_code);
|
||||
insta::assert_snapshot!(dumped);
|
||||
@ -552,9 +552,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_can_do_nested_locals() -> Result<()> {
|
||||
let mut config = crate::languages::get_local_configuration(BundledParser::Go).unwrap();
|
||||
let config = crate::languages::get_local_configuration(BundledParser::Go).unwrap();
|
||||
let source_code = include_str!("../testdata/locals-nested.go");
|
||||
let doc = parse_file_for_lang(&mut config, source_code)?;
|
||||
let doc = parse_file_for_lang(config, source_code)?;
|
||||
|
||||
let dumped = snapshot_syntax_document(&doc, source_code);
|
||||
insta::assert_snapshot!(dumped);
|
||||
@ -564,9 +564,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_can_do_functions() -> Result<()> {
|
||||
let mut config = crate::languages::get_local_configuration(BundledParser::Go).unwrap();
|
||||
let config = crate::languages::get_local_configuration(BundledParser::Go).unwrap();
|
||||
let source_code = include_str!("../testdata/funcs.go");
|
||||
let doc = parse_file_for_lang(&mut config, source_code)?;
|
||||
let doc = parse_file_for_lang(config, source_code)?;
|
||||
|
||||
let dumped = snapshot_syntax_document(&doc, source_code);
|
||||
insta::assert_snapshot!(dumped);
|
||||
@ -576,9 +576,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_can_do_perl() -> Result<()> {
|
||||
let mut config = crate::languages::get_local_configuration(BundledParser::Perl).unwrap();
|
||||
let config = crate::languages::get_local_configuration(BundledParser::Perl).unwrap();
|
||||
let source_code = include_str!("../testdata/perl.pm");
|
||||
let doc = parse_file_for_lang(&mut config, source_code)?;
|
||||
let doc = parse_file_for_lang(config, source_code)?;
|
||||
|
||||
let dumped = snapshot_syntax_document(&doc, source_code);
|
||||
insta::assert_snapshot!(dumped);
|
||||
@ -588,9 +588,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_can_do_matlab() -> Result<()> {
|
||||
let mut config = crate::languages::get_local_configuration(BundledParser::Matlab).unwrap();
|
||||
let config = crate::languages::get_local_configuration(BundledParser::Matlab).unwrap();
|
||||
let source_code = include_str!("../testdata/locals.m");
|
||||
let doc = parse_file_for_lang(&mut config, source_code)?;
|
||||
let doc = parse_file_for_lang(config, source_code)?;
|
||||
|
||||
let dumped = snapshot_syntax_document(&doc, source_code);
|
||||
insta::assert_snapshot!(dumped);
|
||||
@ -600,9 +600,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_can_do_java() -> Result<()> {
|
||||
let mut config = crate::languages::get_local_configuration(BundledParser::Java).unwrap();
|
||||
let config = crate::languages::get_local_configuration(BundledParser::Java).unwrap();
|
||||
let source_code = include_str!("../testdata/locals.java");
|
||||
let doc = parse_file_for_lang(&mut config, source_code)?;
|
||||
let doc = parse_file_for_lang(config, source_code)?;
|
||||
|
||||
let dumped = snapshot_syntax_document(&doc, source_code);
|
||||
insta::assert_snapshot!(dumped);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use bitvec::prelude::*;
|
||||
use protobuf::Enum;
|
||||
use scip::types::{symbol_information, Descriptor, Document, Occurrence, SymbolInformation};
|
||||
use scip_treesitter::types::PackedRange;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use protobuf::{CodedInputStream, Message};
|
||||
use protobuf::Message;
|
||||
use scip::types::Document;
|
||||
use scip_syntax::{get_locals, get_symbols};
|
||||
use scip_treesitter_languages::parsers::BundledParser;
|
||||
|
||||
use anyhow::Result;
|
||||
use std::{fs::File, io::BufReader, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
@ -28,10 +28,10 @@ enum AnalysisMode {
|
||||
|
||||
impl AnalysisMode {
|
||||
fn locals(self) -> bool {
|
||||
return self == AnalysisMode::Locals || self == AnalysisMode::Full;
|
||||
self == AnalysisMode::Locals || self == AnalysisMode::Full
|
||||
}
|
||||
fn globals(self) -> bool {
|
||||
return self == AnalysisMode::Globals || self == AnalysisMode::Full;
|
||||
self == AnalysisMode::Globals || self == AnalysisMode::Full
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ fn index_command(
|
||||
|
||||
bar.finish();
|
||||
|
||||
eprintln!("");
|
||||
eprintln!();
|
||||
|
||||
eprintln!(
|
||||
"Writing index for {} documents into {}",
|
||||
@ -193,13 +193,10 @@ fn index_content(contents: Vec<u8>, parser: BundledParser, options: &Options) ->
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(document);
|
||||
Ok(document)
|
||||
}
|
||||
|
||||
fn write_message_to_file<P>(
|
||||
path: P,
|
||||
msg: impl protobuf::Message,
|
||||
) -> Result<(), Box<dyn std::error::Error>>
|
||||
fn write_message_to_file<P>(path: P, msg: impl Message) -> Result<(), Box<dyn std::error::Error>>
|
||||
where
|
||||
P: AsRef<std::path::Path>,
|
||||
{
|
||||
@ -213,44 +210,40 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_index_from_file(file: PathBuf) -> scip::types::Index {
|
||||
let mut candidate_idx = scip::types::Index::new();
|
||||
let candidate_f = File::open(file).unwrap();
|
||||
|
||||
let mut reader = BufReader::new(candidate_f);
|
||||
let mut cis = CodedInputStream::from_buf_read(&mut reader);
|
||||
|
||||
candidate_idx.merge_from(&mut cis).unwrap();
|
||||
return candidate_idx;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::read_index_from_file;
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use assert_cmd::prelude::*;
|
||||
use protobuf::{CodedInputStream, Message};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::{env::temp_dir, path::PathBuf};
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref BINARY_LOCATION: PathBuf = {
|
||||
let mut c: PathBuf;
|
||||
match std::env::var("SCIP_CLI_LOCATION") {
|
||||
Ok(va) => {
|
||||
c = {
|
||||
std::env::current_dir().unwrap().join(va)
|
||||
}
|
||||
}
|
||||
_ => c = cargo_bin("scip-treesitter-cli")
|
||||
Ok(va) => std::env::current_dir().unwrap().join(va),
|
||||
_ => cargo_bin("scip-treesitter-cli"),
|
||||
}
|
||||
|
||||
c
|
||||
};
|
||||
}
|
||||
|
||||
use scip_treesitter::snapshot::{dump_document_with_config, EmitSymbol, SnapshotOptions};
|
||||
|
||||
fn read_index_from_file(file: PathBuf) -> scip::types::Index {
|
||||
let mut candidate_idx = scip::types::Index::new();
|
||||
let candidate_f = File::open(file).unwrap();
|
||||
|
||||
let mut reader = BufReader::new(candidate_f);
|
||||
let mut cis = CodedInputStream::from_buf_read(&mut reader);
|
||||
|
||||
candidate_idx.merge_from(&mut cis).unwrap();
|
||||
candidate_idx
|
||||
}
|
||||
|
||||
fn snapshot_syntax_document(doc: &scip::types::Document, source: &str) -> String {
|
||||
dump_document_with_config(
|
||||
doc,
|
||||
@ -284,7 +277,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare(temp: &PathBuf, files: &HashMap<PathBuf, String>) {
|
||||
fn prepare(temp: &Path, files: &HashMap<PathBuf, String>) {
|
||||
for (path, contents) in files.iter() {
|
||||
let file_path = temp.join(path);
|
||||
write_file(&file_path, contents);
|
||||
|
||||
@ -372,7 +372,7 @@ impl<'a> DocumentGenerator<'a> {
|
||||
Some(char) => char.0,
|
||||
None => {
|
||||
line_contents.chars().count()
|
||||
- (if line_contents.ends_with("\n") { 1 } else { 0 })
|
||||
- (if line_contents.ends_with('\n') { 1 } else { 0 })
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ use std::path;
|
||||
|
||||
use protobuf::Message;
|
||||
use rocket::serde::json::{json, Json, Value as JsonValue};
|
||||
use scip_syntax::get_globals;
|
||||
use scip_treesitter_languages::parsers::BundledParser;
|
||||
use serde::Deserialize;
|
||||
use sg_syntax::{ScipHighlightQuery, SourcegraphQuery};
|
||||
|
||||
@ -20,6 +20,7 @@ go_binary(
|
||||
go_cross_binary(
|
||||
name = "init-sg-darwin-arm64",
|
||||
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
|
||||
tags = ["manual"],
|
||||
target = ":init-sg",
|
||||
visibility = ["//testing:__pkg__"],
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user