Something went wrong. Try again.
fork of Gleam compiler for Lua backend forked from gleam.run/gleam
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: 2023 The Gleam contributors
use insta::assert_debug_snapshot;use itertools::Itertools;use lsp_types::{CompletionItem, Position};
use super::*;
pub fn show_complete(code: &str, position: Position) -> String { let mut str: String = "".into(); for (line_number, line) in code.lines().enumerate() { let same_line = line_number as u32 == position.line; if !same_line { str.push_str(line); } else { str.push_str(&line[0..position.character as usize]); str.push('|'); str.push_str(&line[position.character as usize..]); }
str.push('\n'); }
str}
fn apply_completion(src: &str, completions: Vec<CompletionItem>, value: &str) -> String { let completion = completions .iter() .find(|c| c.label == value) .unwrap_or_else(|| panic!("no completion with value `{value}`"));
let mut edits = vec![]; if let Some(lsp_types::CompletionItemTextEdit::TextEdit(edit)) = &completion.text_edit { edits.push(edit.clone()); } apply_code_edit(src, edits)}
#[macro_export]macro_rules! assert_apply_completion { ($project:expr, $name:literal, $position:expr) => { let src = $project.src; let completions = completion($project, $position); let output = format!( "{}\n\n----- After applying completion -----\n{}", show_complete(src, $position), apply_completion(src, completions, $name) ); insta::assert_snapshot!(insta::internals::AutoName, output, src); };}
#[macro_export]macro_rules! assert_completion { ($project:expr) => { let src = $project.src; let result = completion_with_prefix($project, ""); let output = format!( "{}\n\n----- Completion content -----\n{}", show_complete(src, Position::new(0, 0)), format_completion_results(result) ); insta::assert_snapshot!(insta::internals::AutoName, output, src); }; ($project:expr, $position:expr) => { let src = $project.src; let result = completion($project, $position); let output = format!( "{}\n\n----- Completion content -----\n{}", show_complete(src, $position), format_completion_results(result) ); insta::assert_snapshot!(insta::internals::AutoName, output, src); };}
#[macro_export]macro_rules! assert_completion_with_prefix { ($project:expr, $prefix:expr) => { let src = $project.src; let result = completion_with_prefix($project, $prefix); let line = 1 + $prefix.lines().count(); let output = format!( "{}\n\n----- Completion content -----\n{}", show_complete(src, Position::new(line as u32, 0)), format_completion_results(result) ); insta::assert_snapshot!(insta::internals::AutoName, output, src); };}
fn format_completion_results(completions: Vec<CompletionItem>) -> EcoString { use std::fmt::Write; let mut buffer: EcoString = "".into();
for CompletionItem { label, label_details, kind, detail, documentation, #[allow(deprecated)] deprecated, preselect, sort_text, filter_text, insert_text, insert_text_format, insert_text_mode, text_edit, additional_text_edits, command, commit_characters, data, tags, text_edit_text, } in completions { assert!(deprecated.is_none()); assert!(preselect.is_none()); assert!(filter_text.is_none()); assert!(insert_text.is_none()); assert!(insert_text_format.is_none()); assert!(insert_text_mode.is_none()); assert!(command.is_none()); assert!(commit_characters.is_none()); assert!(data.is_none()); assert!(tags.is_none()); assert!(text_edit_text.is_none());
buffer.push_str(&label);
if let Some(kind) = kind { write!(buffer, "\n kind: {kind:?}").unwrap(); }
if let Some(detail) = detail { write!(buffer, "\n detail: {detail}").unwrap(); }
if let Some(sort_text) = sort_text { write!(buffer, "\n sort: {sort_text}").unwrap(); }
if let Some(label_details) = label_details { assert!(label_details.detail.is_none()); if let Some(desc) = label_details.description { write!(buffer, "\n desc: {desc}").unwrap(); } }
if let Some(documentation) = documentation { let lsp_types::Documentation::MarkupContent(m) = documentation else { panic!("unexpected docs in test {documentation:?}"); }; match m.kind { lsp_types::MarkupKind::Markdown => (), lsp_types::MarkupKind::PlainText => { panic!("unexpected docs markup kind {:?}", m.kind) } }; write!(buffer, "\n docs: {:?}", m.value).unwrap(); }
let edit = |buffer: &mut EcoString, e: lsp_types::TextEdit| { let a = e.range.start.line; let b = e.range.start.character; let c = e.range.end.line; let d = e.range.end.character; write!(buffer, "\n [{a}:{b}-{c}:{d}]: {:?}", e.new_text).unwrap(); };
if let Some(text_edit) = text_edit { let lsp_types::CompletionItemTextEdit::TextEdit(e) = text_edit else { panic!("unexpected text edit in test {text_edit:?}"); }; buffer.push_str("\n edits:"); edit(&mut buffer, e); }
for e in additional_text_edits.unwrap_or_default() { edit(&mut buffer, e); }
buffer.push('\n'); }
buffer}
fn completion(tester: TestProject<'_>, position: Position) -> Vec<CompletionItem> { tester.at(position, |engine, param, src| { let response = engine.completion(param, src);
let mut completions = response.result.unwrap().unwrap_or_default(); completions.sort_by(|a, b| a.label.cmp(&b.label)); completions })}
fn completion_with_prefix(tester: TestProject<'_>, prefix: &str) -> Vec<CompletionItem> { let src = &format!("{}fn typing_in_here() {{\n 0\n}}\n {}", prefix, tester.src); let tester = TestProject { src, ..tester }; // Put the cursor inside the "typing_in_here" fn body. let line = 1 + prefix.lines().count(); completion(tester, Position::new(line as u32, 0)) .into_iter() .filter(|c| c.label != "typing_in_here") .collect_vec()}
#[test]fn completions_for_outside_a_function() { let code = "
pub fn main() { 0}";
assert_completion!(TestProject::for_source(code), Position::new(0, 0));}
#[test]fn local_public_function() { let code = "pub fn main() { 0}";
assert_completion!(TestProject::for_source(code));}
#[test]fn local_public_function_with_documentation() { let code = "/// Hellopub fn main() { 0}";
assert_completion!(TestProject::for_source(code));}
#[test]fn local_public_enum() { let code = "pub type Direction { Left Right}";
assert_completion!(TestProject::for_source(code));}
#[test]fn local_public_record() { let code = "pub type Box {/// Hello Box(Int, Int, Float)}";
assert_completion!(TestProject::for_source(code));}
#[test]fn local_public_enum_with_documentation() { let code = "pub type Direction { /// Hello Left /// Goodbye Right}";
assert_completion!(TestProject::for_source(code));}
#[test]fn local_public_record_with_documentation() { let code = "pub type Box { Box(Int, Int, Float)}";
assert_completion!(TestProject::for_source(code));}
#[test]fn imported_module_function() { let code = "import dep"; let dep = "pub fn wobble() { Nil}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn importable_module_function() { let code = ""; let dep = "pub fn wobble() { Nil}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn importable_module_function_with_existing_imports() { let code = "//// Some module comments// Some other whitespace
import dep2"; let dep = "pub fn wobble() { Nil}"; let dep2 = "pub fn wobble() { Nil}";
assert_completion!( TestProject::for_source(code) .add_module("dep", dep) .add_module("dep2", dep2) );}
#[test]fn importable_module_function_from_deep_module() { let code = ""; let dep = "pub fn wobble() { Nil}";
assert_completion!(TestProject::for_source(code).add_module("a/b/dep", dep));}
#[test]fn completions_for_type_import_completions_without_brackets() { let src = "import dep."; let dep = "pub opaque type Wibble { Wibble(wibble: String, wobble: Int)}"; let position = Position::new(0, 11); let tester = TestProject::for_source("import dep").add_module("dep", dep); let mut io = LanguageServerTestIO::new(); let mut engine = tester.build_engine(&mut io); // pass a valid src to compile once _ = io.src_module("app", tester.src); let _ = engine.compile_please(); // update src to the one we want to test _ = io.src_module("app", src); let param = tester.build_path(position); let response = engine.completion(param, src.into());
let mut completions = response.result.unwrap().unwrap_or_default(); completions.sort_by(|a, b| a.label.cmp(&b.label)); let output = format!( "{}\n\n----- Completion content -----\n{}", show_complete(src, position), format_completion_results(completions) ); insta::assert_snapshot!(insta::internals::AutoName, output, src);}
#[test]fn importable_adds_extra_new_line_if_no_imports() { let dep = "pub fn wobble() {\nNil\n}"; let code = "";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn importable_adds_extra_new_line_if_import_exists_below_other_definitions() { let dep = "pub fn wobble() {\nNil\n}"; let code = "\nimport dep2\n"; // "code" goes after "fn typing_in_here() {}".
assert_completion!( TestProject::for_source(code) .add_module("dep", dep) .add_module("dep2", "") );}
#[test]fn importable_does_not_add_extra_new_line_if_imports_exist() { let dep = "pub fn wobble() {\nNil\n}"; let prefix = "import wibble\n\n"; let code = "";
assert_completion_with_prefix!( TestProject::for_source(code) .add_module("dep", dep) .add_module("wibble", ""), prefix );}
#[test]fn importable_does_not_add_extra_new_line_if_newline_exists() { let dep = "pub fn wobble() {\nNil\n}"; let prefix = "\n"; let code = "";
assert_completion_with_prefix!( TestProject::for_source(code) .add_module("dep", dep) .add_module("wibble", ""), prefix );}
#[test]fn imported_public_enum() { let code = "import dep"; let dep = "pub type Direction { Left Right}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn imported_public_record() { let code = "import dep"; let dep = "pub type Box { Box(Int)}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn imported_unqualified_module_function() { let code = "import dep.{wobble}"; let dep = "pub fn wobble() { Nil}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn imported_unqualified_public_enum() { let code = "import dep.{Left}"; let dep = "pub type Direction { Left Right}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn imported_unqualified_public_record() { let code = "import dep.{Box}"; let dep = "pub type Box { Box(Int)}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn private_function() { let code = "fn private() { 1}"; let dep = "";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn private_type() { let code = "type Wibble { Wobble}"; let dep = "";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn opaque_type() { let code = "pub opaque type Wibble { Wobble}"; let dep = "";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn private_function_in_dep() { let code = "import dep"; let dep = "fn private() { 1}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn private_type_in_dep() { let code = "import dep"; let dep = "type Wibble { Wobble}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn in_custom_type_definition() { let code = "import dep"; let dep = "type Wibble { Wobble}";
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn for_custom_type_definition() { let code = "pub type Wibble { Wobble}";
assert_completion!(TestProject::for_source(code), Position::new(2, 0));}
#[test]fn for_type_alias() { let code = "pub type Wibble = Result( String, String)";
assert_completion!(TestProject::for_source(code), Position::new(2, 0));}
#[test]fn for_function_arguments() { let code = "pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!(TestProject::for_source(code), Position::new(2, 0));}
#[test]fn imported_type() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let code = "import dep
pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(3, 0) );}
#[test]fn imported_type_cursor_after_dot() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let code = "import dep
pub fn wibble( _: dep.Zoo,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(3, 12) );}
#[test]fn imported_type_cursor_after_dot_other_matching_modules() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let dep2 = "pub type Zoo = List(String)type Private = List(String)"; let code = "import depimport dep2
pub fn wibble( _: dep.Zoo,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code) .add_module("dep", dep) .add_module("dep2", dep2), Position::new(4, 12) );}
#[test]fn imported_type_cursor_after_dot_other_modules() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let other = "pub type Zoo = List(String)type Private = List(String)"; let code = "import dep
pub fn wibble( _: dep.Zoo,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code) .add_module("dep", dep) .add_module("other", other), Position::new(3, 12) );}
#[test]fn imported_type_cursor_mid_phrase_other_modules() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let other = "pub type Zoo = List(String)type Private = List(String)"; let code = "import dep
pub fn wibble( _: dep.Zoo,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code) .add_module("dep", dep) .add_module("other", other), Position::new(3, 8) );}
#[test]fn importable_type() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let code = "
pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(3, 0) );}
#[test]fn importable_type_with_existing_imports_at_top() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let dep2 = "pub type Zoo = List(String)type Private = List(String)"; let code = "import dep2
pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code) .add_module("dep", dep) .add_module("dep2", dep2), Position::new(3, 0) );}
#[test]fn importable_type_with_existing_imports() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let dep2 = "pub type Zoo = List(String)type Private = List(String)"; let code = "//// Some module comments// Some other whitespace
import dep2
pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code) .add_module("dep", dep) .add_module("dep2", dep2), Position::new(7, 0) );}
#[test]fn importable_type_from_deep_module() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let code = "
pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code).add_module("a/b/dep", dep), Position::new(3, 0) );}
#[test]fn unqualified_imported_type() { let dep = "pub type Zoo = List(String)type Private = List(String)"; let code = "import dep.{type Zoo}
pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(3, 0) );}
#[test]fn local_private_type() { let code = "type Zoo = Int
pub fn wibble( x: String,) -> String { \"ok\"}";
assert_completion!(TestProject::for_source(code), Position::new(4, 0));}
#[test]fn local_variable() { let code = "pub fn main(wibble: Int) { let wobble = 1 w
let wabble = 2}";
assert_completion!(TestProject::for_source(code), Position::new(3, 3));}
#[test]fn local_variable_anonymous_function() { let code = "pub fn main() { let add_one = fn(wibble: Int) { wibble + 1 } add_one(1)}";
assert_completion!(TestProject::for_source(code), Position::new(2, 40));}
#[test]fn local_variable_nested_anonymous_function() { let code = "pub fn main() { let add_one = fn(wibble: Int) { let wabble = 1 let add_two = fn(wobble: Int) { wobble + 2 } wibble + add_two(1) } add_one(1)}";
assert_completion!(TestProject::for_source(code), Position::new(4, 42));}
#[test]fn local_variable_ignore_anonymous_function_args() { let code = "pub fn main() { let add_one = fn(wibble: Int) { wibble + 1 } let wobble = 1 w}";
assert_completion!(TestProject::for_source(code), Position::new(4, 3));}
#[test]fn local_variable_ignore_anonymous_function_args_nested() { let code = "pub fn main() { let add_one = fn(wibble: Int) { let wabble = 1 let add_two = fn(wobble: Int) { wobble + 2 } wibble + add_two(1) } add_one(1)}";
assert_completion!(TestProject::for_source(code), Position::new(5, 10));}
#[test]fn local_variable_ignore_anonymous_function_returned() { let code = "pub fn main() { fn(wibble: Int) { let wabble = 1 let add_two = fn(wobble: Int) { wobble + 2 } wibble + add_two(1) }}";
assert_completion!(TestProject::for_source(code), Position::new(5, 10));}
#[test]fn local_variable_case_expression() { let code = "pub fn main() { case True { True as wibble -> { todo } False -> { todo } }}";
assert_completion!(TestProject::for_source(code), Position::new(3, 25));}
#[test]fn local_variable_inside_nested_exprs() { let code = r#"type Wibble { Wobble(List(#(Bool))) }fn wibble() { Wobble([#(!{ let wibble = True wibble })]) todo}"#;
assert_completion!(TestProject::for_source(code), Position::new(5, 7));}
#[test]fn local_variable_pipe() { let code = "pub fn main() { let add_one = fn(wibble: Int) { wibble + 1 } let wobble = 1 wobble |> add_one}";
assert_completion!(TestProject::for_source(code), Position::new(4, 19));}
#[test]fn local_variable_pipe_with_args() { let code = "pub fn main() { let add_one = fn(wibble: Int, wobble: Int) { wibble + wobble } let wobble = 1 let wibble = 2 wobble |> add_one(1, wibble)}";
assert_completion!(TestProject::for_source(code), Position::new(5, 29));}
#[test]fn local_variable_function_call() { let code = "fn add_one(wibble: Int) -> Int { wibble + 1}
pub fn main() { let wobble = 1 add_one(wobble)}";
assert_completion!(TestProject::for_source(code), Position::new(7, 16));}
#[test]fn local_variable_ignored() { let code = "fn wibble() { let a = 1 let _b = 2
}"; assert_completion!(TestProject::for_source(code), Position::new(4, 0));}
#[test]fn local_variable_as() { let code = "fn wibble() { let b as c = 5
}"; assert_completion!(TestProject::for_source(code), Position::new(3, 0));}
#[test]fn local_variable_tuple() { let code = "fn wibble() { let assert #([d, e] as f, g) = #([0, 1], 2)
}"; assert_completion!(TestProject::for_source(code), Position::new(3, 0));}
#[test]fn local_variable_bit_array() { let code = "fn wibble() { let assert <<h:1>> as i = <<1:1>>
}"; assert_completion!(TestProject::for_source(code), Position::new(3, 0));}
#[test]fn local_variable_string() { let code = r#"fn wibble() { let assert "a" <> j = "ab"
}"#; assert_completion!(TestProject::for_source(code), Position::new(3, 0));}
#[test]fn local_variable_ignore_within_function() { let code = "fn main(a, b, z) { Nil}"; assert_completion!(TestProject::for_source(code), Position::new(1, 14));}
#[test]fn internal_values_from_root_package_are_in_the_completions() { let dep = r#"@external(erlang, "rand", "uniform")@internal pub fn random_float() -> Float@internal pub fn main() { 0 }@internal pub type Wibble { Wobble }@internal pub const wibble = 1"#;
assert_completion!(TestProject::for_source("import dep").add_module("dep", dep));}
#[test]fn internal_types_from_root_package_are_in_the_completions() { let code = "import dep
pub fn wibble( _: String,) -> Nil { Nil}";
let dep = r#"@internal pub type Alias = Int@internal pub type AnotherType { Constructor }"#; assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(3, 0) );}
#[test]fn internal_values_from_the_same_module_are_in_the_completions() { let code = r#"@external(erlang, "rand", "uniform")@internal pub fn random_float() -> Float@internal pub fn main() { 0 }@internal pub type Wibble { Wobble }@internal pub const wibble = 1"#;
assert_completion!(TestProject::for_source(code));}
#[test]fn internal_types_from_the_same_module_are_in_the_completions() { let code = "@internal pub type Alias = Result(Int, String)@internal pub type AnotherType { Wibble}";
assert_completion!(TestProject::for_source(code), Position::new(3, 0));}
#[test]fn internal_types_from_a_dependency_are_ignored() { let code = "import dep
pub fn wibble( _: String,) -> Nil { Nil}";
let dep = r#"@internal pub type Alias = Int@internal pub type AnotherType { Constructor }"#;
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(3, 0) );}
#[test]fn internal_values_from_a_dependency_are_ignored() { let dep = r#"@external(erlang, "rand", "uniform")@internal pub fn random_float() -> Float@internal pub fn main() { 0 }@internal pub type Wibble { Wobble }@internal pub const wibble = 1"#;
assert_completion!(TestProject::for_source("import dep").add_dep_module("dep", dep));}
#[test]fn completions_for_an_import() { let code = "import dep
pub fn main() { 0}"; let dep = "";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(0, 10) );}
#[test]fn completions_for_an_import_no_test() { let code = "import gleam
pub fn main() { 0}"; let test = "import gleam
pub fn main() { 0}";
assert_completion!( TestProject::for_source(code).add_test_module("my_tests", test), Position::new(0, 10) );}
#[test]fn completions_for_an_import_while_in_test() { let code = "import gleam
pub fn main() { 0}"; let test = "import gleam
pub fn main() { 0}"; let test_helper = "pub fn test_helper() { 0}";
let (mut engine, position_param) = TestProject::for_source(code) .add_test_module("my_test", test) .add_test_module("test_helper", test_helper) .positioned_with_io_in_test(Position::new(0, 10), "my_test");
let response = engine.completion(position_param, code.into());
let mut completions = response.result.unwrap().unwrap_or_default(); completions.sort_by(|a, b| a.label.cmp(&b.label));
assert_debug_snapshot!(completions,);}
#[test]fn completions_for_an_import_while_in_dev() { let code = "import gleam
pub fn main() { 0}"; let dev_helper = "pub fn dev_helper() { 0}";
let position = Position::new(0, 12); let (mut engine, position_param) = TestProject::for_source(code) .add_test_module("my_test", code) .add_dev_module("my_dev_code", code) .add_dev_module("dev_helper", dev_helper) .positioned_with_io_in_dev(position, "my_dev_code");
let response = engine.completion(position_param, code.into());
let mut completions = response.result.unwrap().unwrap_or_default(); completions.sort_by(|a, b| a.label.cmp(&b.label));
let output = format!( "{}\n\n----- Completion content -----\n{}", show_complete(code, position), format_completion_results(completions) ); insta::assert_snapshot!(insta::internals::AutoName, output, code);}
#[test]fn completions_for_an_import_with_docs() { let code = "import gleam
pub fn main() { 0}"; let dep = "//// Some package//// documentation!
pub fn main() { 1 } ";
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(0, 10) );}
#[test]fn completions_for_an_import_from_dependency() { let code = "import gleam
pub fn main() { 0}"; let dep = "";
assert_completion!( TestProject::for_source(code).add_hex_module("example_module", dep), Position::new(0, 10) );}
#[test]fn completions_for_an_import_not_from_indirect_dependency() { let code = "import gleam
pub fn main() { 0}"; let dep = "";
assert_completion!( TestProject::for_source(code) .add_hex_module("example_module", dep) .add_indirect_hex_module("indirect_module", ""), Position::new(0, 10) );}
#[test]fn completions_for_an_import_not_from_dev_dependency() { let code = "import gleam
pub fn main() { 0}"; let dep = "";
assert_completion!( TestProject::for_source(code) .add_hex_module("example_module", dep) .add_dev_hex_module("indirect_module", ""), Position::new(0, 10) );}
#[test]fn completions_for_an_import_not_from_dev_dependency_in_test() { let code = "import gleam
pub fn main() { 0}"; let test = "import gleam
pub fn main() { 0}"; let dep = "";
let (mut engine, position_param) = TestProject::for_source(code) .add_test_module("my_test", test) .add_hex_module("example_module", dep) .add_dev_hex_module("indirect_module", "") .positioned_with_io_in_test(Position::new(0, 10), "my_test");
let response = engine.completion(position_param, code.into());
let mut completions = response.result.unwrap().unwrap_or_default(); completions.sort_by(|a, b| a.label.cmp(&b.label));
assert_debug_snapshot!(completions,);}
#[test]fn completions_for_an_import_not_from_dev_dependency_in_dev() { let code = "import gleam
pub fn main() { 0}"; let dev = "import gleam
pub fn main() { 0}"; let dep = "";
let position = Position::new(0, 10); let (mut engine, position_param) = TestProject::for_source(code) .add_dev_module("my_dev_module", dev) .add_hex_module("example_module", dep) .add_dev_hex_module("indirect_module", "") .positioned_with_io_in_dev(position, "my_dev_module");
let response = engine.completion(position_param, code.into());
let mut completions = response.result.unwrap().unwrap_or_default(); completions.sort_by(|a, b| a.label.cmp(&b.label));
let output = format!( "{}\n\n----- Completion content -----\n{}", show_complete(dev, position), format_completion_results(completions) ); insta::assert_snapshot!(insta::internals::AutoName, output, dev);}
#[test]fn completions_for_an_import_from_dependency_with_docs() { let code = "//// Main package//// documentation!
import gleam
pub fn main() { 0}"; let dep = "//// Some package//// documentation!
pub fn main() { 1 } ";
assert_completion!( TestProject::for_source(code).add_hex_module("example_module", dep), Position::new(3, 10) );}
#[test]fn completions_for_an_import_start() { let code = "import gleam
pub fn main() { 0}"; let dep = "";
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(0, 0) );}
#[test]fn completions_for_an_import_preceeding_whitespace() { let code = " import gleam
pub fn main() { 0}"; let dep = "";
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(0, 2) );}
#[test]fn internal_modules_from_same_package_are_included() { let code = "import gleam
pub fn main() { 0}"; let internal_name = format!("{LSP_TEST_ROOT_PACKAGE_NAME}/internal");
assert_completion!( TestProject::for_source(code) // Not included .add_dep_module("dep/internal", "") // Included .add_module(&internal_name, ""), Position::new(0, 0) );}
#[test]fn completions_for_an_unqualified_import() { let code = "import dep.{}
pub fn main() { 0}"; let dep = "pub const wibble = \"wibble\"const wobble = \"wobble\"@internalpub const wabble = \"wabble\"
pub fn myfun() { 0}
pub type Wibble = String";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(1, 12) );}
#[test]fn completions_for_an_unqualified_import_on_new_line() { let code = "import dep.{ wibble,
}
pub fn main() { 0}"; let dep = "pub const wibble = \"wibble\"
pub fn myfun() { 0}
pub type Wibble = String";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), // putting cursor at beginning of line because some formatters // remove the empty whitespace in the test code. // Does also work with (3, 2) when empty spaces are not removed. Position::new(3, 0) );}
#[test]fn completions_for_an_unqualified_import_already_imported() { let code = "import dep.{wibble,wabble,type Wibble}
pub fn main() { 0}"; let dep = "pub const wibble = \"wibble\"const wobble = \"wobble\"@internalpub const wabble = \"wabble\"
pub fn myfun() { 0}
pub type Wibble = String";
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(1, 12) );}
#[test]fn completions_for_a_function_arg_annotation() { let code = "pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!(TestProject::for_source(code), Position::new(2, 11));}
#[test]fn completions_for_a_function_return_annotation() { let code = "pub fn wibble( _: String,) -> Nil { Nil}";
assert_completion!(TestProject::for_source(code), Position::new(3, 7));}
#[test]fn completions_for_a_var_annotation() { let code = "pub fn main() { let wibble: Int = 7}";
assert_completion!(TestProject::for_source(code), Position::new(2, 16));}
#[test]fn completions_for_a_const_annotation() { let code = "
const wibble: Int = 7
pub fn main() { let wibble: Int = 7}";
assert_completion!(TestProject::for_source(code), Position::new(2, 16));}
#[test]fn ignore_completions_in_empty_comment() { // Reproducing issue #2161 let code = "pub fn main() { case 0 { // _ -> 1 }}";
// End of the comment (right after the last `/`) assert_eq!( completion(TestProject::for_source(code), Position::new(3, 6)), vec![], );}
#[test]fn ignore_completions_in_middle_of_comment() { // Reproducing issue #2161 let code = "pub fn main() { case 0 { // comment _ -> 1 }}";
// At `c` assert_eq!( completion(TestProject::for_source(code), Position::new(3, 7)), vec![], );}
#[test]fn ignore_completions_in_end_of_comment() { // Reproducing issue #2161 let code = "pub fn main() { case 0 { // comment _ -> 1 }}";
// End of the comment (after `t`) assert_eq!( completion(TestProject::for_source(code), Position::new(3, 14)), vec![], );}
#[test]fn ignore_completions_inside_empty_string() { let code = "pub fn main() { \"\"}";
assert_eq!( completion(TestProject::for_source(code), Position::new(2, 2)), vec![], );}
#[test]fn ignore_completions_inside_string() { let code = "pub fn main() { \"Ok()\"}";
assert_eq!( completion(TestProject::for_source(code), Position::new(2, 5)), vec![], );}
#[test]fn completions_for_record_access() { let code = "pub type Wibble { Wibble(wibble: Int, wobble: Int) Wobble(wabble: Int, wobble: Int)}
fn fun() { let wibble = Wibble(1, 2) wibble.wobble}";
assert_completion!(TestProject::for_source(code), Position::new(8, 15));}
#[test]fn completions_for_private_record_access() { let code = "type Wibble { Wibble(wibble: Int, wobble: Int) Wobble(wabble: Int, wobble: Int)}
fn fun() { let wibble = Wibble(1, 2) wibble.wobble}";
assert_completion!(TestProject::for_source(code), Position::new(8, 15));}
#[test]fn completions_for_record_access_known_variant() { let code = "type Wibble { Wibble(a: Int, b: Int, c: Int, d: Int) Wobble(z: Bool)}
fn fun(some_wibble: Wibble) { case some_wibble { Wibble(..) as w -> w.a Wobble(..) -> panic }}";
assert_completion!(TestProject::for_source(code), Position::new(8, 26));}
#[test]fn completions_for_record_access_unknown_variant() { let code = "type Wibble { Wibble(a: Int, b: Int, c: Int, d: Int) Wobble(a: Int, z: Bool)}
fn fun(some_wibble: Wibble) { some_wibble.a}";
assert_completion!(TestProject::for_source(code), Position::new(7, 15));}
#[test]fn completions_for_record_labels() { let code = "pub type Wibble { Wibble(wibble: String, wobble: Int)}
fn fun() { // completion inside parens below includes labels let wibble = Wibble()}";
assert_completion!(TestProject::for_source(code), Position::new(6, 22));}
#[test]fn completions_for_imported_record_labels() { let code = "import dep
fn fun() { // completion inside parens below includes labels let wibble = dep.Wibble()}"; let dep = "pub type Wibble { Wibble(wibble: String, wobble: Int)}";
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(4, 26) );}
#[test]fn no_completions_for_imported_internal_record_fields() { let code = "import dep
fn fun(wibble: dep.Wibble) { wibble. // ^ We should see no completions here!}"; let dep = "@internalpub type Wibble { Wibble(wibble: String, wobble: Int)}";
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(4, 9) );}
#[test]fn completions_for_internal_record_fields_inside_the_same_module() { let code = "@internalpub type Wibble { Wibble(wibble: String, wobble: Int)}
fn fun(wibble: Wibble) { wibble. // ^ We should see some completions here!}";
assert_completion!(TestProject::for_source(code), Position::new(7, 9));}
#[test]fn completions_for_imported_record_fields() { let code = "import dep
fn fun(wibble: dep.Wibble) { wibble. // ^ We should see wibble and wobble completions here!}"; let dep = "pub type Wibble { Wibble(wibble: String, wobble: Int)}";
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(4, 9) );}
#[test]fn completions_for_function_labels() { let code = "fn wibble(wibble arg1: String, wobble arg2: String) { arg1 <> arg2}
fn fun() { // completion inside parens below includes labels let wibble = wibble()}";
assert_completion!(TestProject::for_source(code), Position::new(6, 22));}
#[test]fn completions_for_imported_function_labels() { let code = "import dep
fn fun() { // completion inside parens below includes labels let wibble = dep.wibble()}"; let dep = "pub fn wibble(wibble arg1: String, wobble arg2: String) { arg1 <> arg2}";
assert_completion!( TestProject::for_source(code).add_dep_module("dep", dep), Position::new(4, 26) );}
#[test]fn no_completion_inside_comment_that_is_more_than_three_lines() { let code = "import list
// list.// list.fn fun() { // list. todo}";
let dep = "pub fn map() {}"; let completions = completion( TestProject::for_source(code).add_dep_module("list", dep), Position::new(5, 10), ); assert_eq!(completions, vec![],);}
#[test]fn completions_for_prelude_values() { let code = "pub fn main() { let my_bool = T}";
assert_completion!(TestProject::for_source(code), Position::new(2, 17));}
#[test]fn variable_shadowing() { let code = "pub fn main() { let x = 1 let x = [1, 2]
}";
assert_completion!(TestProject::for_source(code), Position::new(4, 0));}
#[test]fn argument_shadowing() { let code = "pub fn main(x: Int) { fn(x: Float) {
}}";
assert_completion!(TestProject::for_source(code), Position::new(3, 0));}
#[test]fn argument_variable_shadowing() { let code = "pub fn main(x: Int) { let x = [1, 2]
}";
assert_completion!(TestProject::for_source(code), Position::new(3, 0));}
// https://github.com/gleam-lang/gleam/issues/3833#[test]fn autocomplete_doesnt_delete_the_piece_of_code_that_comes_after() { let code = "import listpub fn main(x: Int) { list.list.filter([1, 2, 3], todo)}"; let list = "pub fn filter(_, _) { [] }pub fn map(_, _) { [] }";
assert_apply_completion!( TestProject::for_source(code).add_dep_module("list", list), "list.map", Position::new(3, 7) );}
#[test]fn autocomplete_doesnt_delete_the_piece_of_code_that_comes_after_2() { let code = "import listpub fn main(x: Int) { list.mlist.filter([1, 2, 3], todo)}"; let list = "pub fn filter(_, _) { [] }pub fn map(_, _) { [] }";
assert_apply_completion!( TestProject::for_source(code).add_dep_module("list", list), "list.map", Position::new(3, 8) );}
#[test]fn case_subject() { let code = "pub fn main(something: Bool) { case so}";
assert_apply_completion!( TestProject::for_source(code), "something", Position::new(2, 9) );}
#[test]fn constant() { let code = "const hello = 10const world = he";
assert_completion!(TestProject::for_source(code), Position::new(2, 16));}
#[test]fn constant_with_many_options() { let code = "import wibble.{Wobble}
type Wibble { Wibble}
const pi = 3.14159
fn some_function() { todo}
const my_constant = a";
assert_completion!( TestProject::for_source(code).add_hex_module("wibble", "pub type Wibble { Wobble Wubble }"), Position::new(13, 21) );}
#[test]fn constant_with_module_select() { let code = "import wibble
type Wibble { Wibble}
const pi = 3.14159
fn some_function() { todo}
const my_constant = wibble.W";
assert_completion!( TestProject::for_source(code).add_hex_module( "wibble", "pub type Wibble { Wobble Wubble }pub const some_constant = 1pub fn some_function() { todo }" ), Position::new(13, 28) );}
#[test]fn labelled_arguments() { let code = "pub type Wibble { Wibble(wibble: Int, wobble: Float)}
pub fn main() { Wibble(w)}";
assert_completion!(TestProject::for_source(code), Position::new(6, 10));}
#[test]fn labelled_arguments_with_existing_label() { // This should only suggest the `wobble:` label let code = "pub type Wibble { Wibble(wibble: Int, wobble: Float)}
pub fn main() { Wibble(wibble: 10, w)}";
assert_completion!(TestProject::for_source(code), Position::new(6, 22));}
#[test]fn labelled_arguments_after_label() { // This should not suggest any labels, as `wibble: wibble:` is not valid syntax. let code = "pub type Wibble { Wibble(wibble: Int, wobble: Float)}
pub fn main() { Wibble(wibble: w)}";
assert_completion!(TestProject::for_source(code), Position::new(6, 18));}
#[test]fn labelled_arguments_function_call() { let code = "pub fn divide(x: Int, by y: Int) { x / y }
pub fn main() { divide(10, b)}";
assert_completion!(TestProject::for_source(code), Position::new(4, 14));}
#[test]fn labelled_arguments_from_different_module() { let code = "import wibble
pub fn main() { wibble.divide(10, b)}";
assert_completion!( TestProject::for_source(code) .add_hex_module("wibble", "pub fn divide(x: Int, by y: Int) { x / y }"), Position::new(4, 21) );}
#[test]fn no_label_completions_in_nested_expression() { // Since we are completing inside a list, labels are no longer available let code = "pub type Wibble { Wibble(wibble: Int, wobble: Float)}
pub fn main() { Wibble([w])}";
assert_completion!(TestProject::for_source(code), Position::new(6, 11));}
// https://github.com/gleam-lang/gleam/issues/4625#[test]fn no_variable_completions_before_declaration_in_block() { let code = "pub fn main() { { s let something = 10 }}";
assert_completion!(TestProject::for_source(code), Position::new(3, 5));}
// https://github.com/gleam-lang/gleam/issues/4625#[test]fn no_variable_completions_before_declaration_in_anonymous_function() { let code = "pub fn main() { fn() { s let something = 10 }}";
assert_completion!(TestProject::for_source(code), Position::new(3, 5));}
// https://github.com/gleam-lang/gleam/issues/4625#[test]fn no_variable_completions_after_block_scope() { let code = "pub fn main() { { let something = 10 } s}";
assert_completion!(TestProject::for_source(code), Position::new(5, 3));}
// https://github.com/gleam-lang/gleam/issues/4625#[test]fn no_variable_completions_after_anonymous_function_scope() { let code = "pub fn main() { fn() { let something = 10 } s}";
assert_completion!(TestProject::for_source(code), Position::new(5, 3));}
// https://github.com/gleam-lang/gleam/issues/4625#[test]fn no_variable_completions_after_case_scope() { let code = "pub fn main() { case todo { something -> Nil } s}";
assert_completion!(TestProject::for_source(code), Position::new(5, 3));}
// https://github.com/gleam-lang/gleam/issues/4625#[test]fn no_variable_completions_after_case_clause_scope() { let code = "pub fn main() { case todo { something -> Nil something_else -> s } s}";
assert_completion!(TestProject::for_source(code), Position::new(4, 23));}
// https://github.com/gleam-lang/gleam/issues/4625#[test]fn no_variable_completions_before_case_clause() { let code = "pub fn main() { case todo { something -> s something_else -> Nil } s}";
assert_completion!(TestProject::for_source(code), Position::new(3, 18));}
// https://github.com/gleam-lang/gleam/issues/4652#[test]fn no_completions_in_constant_string() { let code = r#"const x = "io.""#;
let completions = completion( TestProject::for_source(code).add_hex_module("gleam/io", "pub fn println() {todo}"), Position::new(1, 14), ); assert_eq!(completions, vec![],);}
#[test]fn prefer_values_matching_expected_type() { let code = "pub fn main() -> Bool { let wibble = 123 let wubble = True let Wobble = 1.5 w}";
assert_completion!(TestProject::for_source(code), Position::new(5, 3));}
#[test]fn prefer_function_which_returns_expected_type() { let code = "pub fn main() -> Int { a}
fn add(a, b) { a + b }fn sub(a, b) { a - b }fn addf(a, b) { a +. b }";
assert_completion!(TestProject::for_source(code), Position::new(2, 3));}
#[test]fn prefer_function_which_returns_expected_generic_type() { let code = "pub fn main() -> Result(Int, Nil) { let result = Ok(12) let result2 = Error(True) r}";
assert_completion!(TestProject::for_source(code), Position::new(4, 3));}
#[test]fn completion_for_type() { let dep = "pub type Wibble"; let code = "pub fn new() -> wibble.Wibble {}"; assert_completion!( TestProject::for_source(code).add_dep_module("wibble", dep), Position::new(0, 23) );}
#[test]fn completion_for_partially_correct_existing_module_select() { let dep = "pub fn filter() {}"; let code = "import gleam/list
pub fn new() { list.fer// ^ cursor right after the 'f'}"; assert_completion!( TestProject::for_source(code).add_dep_module("gleam/list", dep), Position::new(4, 8) );}
#[test]fn complete_keyword_being_typed() { assert_apply_completion!( TestProject::for_source("pub fn main() { t }"), "todo", Position::new(0, 17) );}
#[test]fn complete_echo_keyword() { assert_apply_completion!( TestProject::for_source("pub fn main() { e wibble }"), "echo", Position::new(0, 17) );}
#[test]fn complete_panic_keyword() { assert_apply_completion!( TestProject::for_source("pub fn main() { wibble(p) }"), "panic", Position::new(0, 24) );}
#[test]fn do_not_show_completions_when_typing_a_number() { assert_completion!( TestProject::for_source( "pub fn main() { 2 }pub fn window_by_2() {}pub fn to_base_32() {}" ), Position::new(1, 17) );}
const OPTION_MODULE: &str = "pub type Option(a) { Some(a) None }pub fn all() {}";
#[test]fn do_not_show_completions_for_module_values_when_typing_an_argument_type() { assert_completion!( TestProject::for_source( "import optionpub fn main(n: option.) {}" ) .add_dep_module("option", OPTION_MODULE), Position::new(2, 22) );}
#[test]fn do_not_show_completions_for_module_values_when_typing_a_return_type() { assert_completion!( TestProject::for_source( "import optionpub fn main() -> option. {}" ) .add_dep_module("option", OPTION_MODULE), Position::new(2, 24) );}
#[test]fn do_not_show_completions_for_module_values_when_typing_a_constructor_type() { assert_completion!( TestProject::for_source( "import optionpub type Wibble { Wibble(option.)}" ) .add_dep_module("option", OPTION_MODULE), Position::new(3, 16) );}
#[test]fn do_not_show_completions_for_module_values_when_typing_an_annotation() { assert_completion!( TestProject::for_source( "import optionpub fn main() { let a: option. = todo}" ) .add_dep_module("option", OPTION_MODULE), Position::new(3, 16) );}
#[test]fn completions_when_typing_list_tail() { assert_completion!( TestProject::for_source( "pub fn main() { let wibble = [1, 2] [3, 4, ..w]}" ), Position::new(3, 12) );}
#[test]fn completions_when_typing_record_update() { assert_completion!( TestProject::for_source( "pub type Wibble { Wibble(a: Int, b: String) }
pub fn main() { let wibble = todo Wibble(..w)}" ), Position::new(5, 12) );}
#[test]fn do_not_show_completions_for_deprecated_values_in_dep() { let code = "import dep"; let dep = r#"@deprecated("Reason")pub fn wibble() { todo}
pub fn wobble() { todo}
@deprecated("Reason")pub type Wibble { Wibble}
pub type Wobble { Wobble}"#;
assert_completion!(TestProject::for_source(code).add_module("dep", dep));}
#[test]fn do_not_show_completions_for_deprecated_values_in_dep_import() { let code = "import dep.{}"; let dep = r#"@deprecated("Reason")pub fn wibble() { todo}
pub fn wobble() { todo}
@deprecated("Reason")pub type Wibble { Wibble}
pub type Wobble { Wobble}"#;
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(0, 12) );}
#[test]fn show_completions_for_local_deprecated_values() { let code = r#"@deprecated("Reason")fn wibble() { todo}
@deprecated("Reason")type Wibble { Wibble}"#;
assert_completion!(TestProject::for_source(code));}
#[test]fn do_not_show_completions_for_deprecated_function_in_dep_while_typing() { let code = "import dep
pub fn wobble() { dep.wibb}"; let dep = r#"@deprecated("Reason")pub fn wibble() { todo}"#;
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(4, 12) );}
#[test]fn do_not_show_completions_for_deprecated_value_in_dep_while_typing() { let code = "import dep
pub fn wobble() { dep.Wibb}"; let dep = r#"@deprecated("Reason")pub type Wibble { Wibble}"#;
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(4, 12) );}
#[test]fn do_not_show_completions_for_deprecated_values_in_dep_after_dot() { let code = "import dep
pub fn wobble() { dep.}"; let dep = r#"@deprecated("Reason")pub fn wibble() { todo}
@deprecated("Reason")pub type Wibble { Wibble}"#;
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(4, 8) );}
#[test]fn do_not_show_completions_for_deprecated_types_in_dep() { let code = "import dep
pub fn wobble() -> W { todo}"; let dep = r#"pub type Wobble { Wobble}
@deprecated("Reason")pub type Wibble { Wibble}"#;
assert_completion!( TestProject::for_source(code).add_module("dep", dep), Position::new(3, 20) );}
#[test]fn _completions_for_deprecated_types_in_dep() { let code = "import wibble
pub fn wobble() -> wibble.Wobble { todo}"; let dep = "pub type Wobble";
assert_apply_completion!( TestProject::for_source(code).add_module("wibble", dep), "wibble.Wobble", Position::new(3, 25) );}
// https://github.com/gleam-lang/gleam/issues/5937#[test]fn completions_for_imported_internal_record_fields_in_same_package() { let code = "import mod
fn fun(wibble: mod.Wibble) { wibble. // ^ `mod` is in the same package so we expect completions here, even though // `Wibble` is internal.}"; let r#mod = "@internalpub type Wibble { Wibble(wibble: String, wobble: Int)}";
assert_completion!( TestProject::for_source(code).add_module("mod", r#mod), Position::new(4, 9) );}