| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163 |
- commit 44b4bf6bc607a3748feb6b1b8a91c42b5e539579
- Author: N. Taylor Mullen <[email protected]>
- Date: Mon Nov 13 15:15:47 2017 -0800
- Cleanup legacy and unintentionally public bits.
-
- - Made `RazorTemplateEngineFactoryService`, `TagHelperResolver`, `RazorDiagnosticJsonConverter` and `RazorLanguageServiceException` internal.
- - Deleted all items in the Legacy folder in VisualStudio.LanguageServices.Razor and `RazorLanguageServiceException`.
-
- #1762
- diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorTemplateEngineFactoryService.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorTemplateEngineFactoryService.cs
- index 7908a9f1169..26ff5b803af 100644
- --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorTemplateEngineFactoryService.cs
- +++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorTemplateEngineFactoryService.cs
- @@ -7,7 +7,7 @@ using Microsoft.CodeAnalysis.Host;
-
- namespace Microsoft.CodeAnalysis.Razor
- {
- - public abstract class RazorTemplateEngineFactoryService : ILanguageService
- + internal abstract class RazorTemplateEngineFactoryService : ILanguageService
- {
- public abstract RazorTemplateEngine Create(string projectPath, Action<IRazorEngineBuilder> configure);
- }
- diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs
- index d246743f59d..a16f46400b7 100644
- --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs
- +++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs
- @@ -7,7 +7,7 @@ using Microsoft.CodeAnalysis.Host;
-
- namespace Microsoft.CodeAnalysis.Razor
- {
- - public abstract class TagHelperResolver : ILanguageService
- + internal abstract class TagHelperResolver : ILanguageService
- {
- public abstract TagHelperResolutionResult GetTagHelpers(Compilation compilation);
-
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDirectiveResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDirectiveResolver.cs
- index f0ce0e7e3f5..9c1eadae887 100644
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDirectiveResolver.cs
- +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDirectiveResolver.cs
- @@ -29,9 +29,10 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
- }
- catch (Exception exception)
- {
- - throw new RazorLanguageServiceException(
- - typeof(DefaultRazorEngineDirectiveResolver).FullName,
- - nameof(GetRazorEngineDirectivesAsync),
- + throw new InvalidOperationException(
- + Resources.FormatUnexpectedException(
- + typeof(DefaultRazorEngineDirectiveResolver).FullName,
- + nameof(GetRazorEngineDirectivesAsync)),
- exception);
- }
- }
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDocumentGenerator.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDocumentGenerator.cs
- index 09b3f66ce8b..b7c0cce0614 100644
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDocumentGenerator.cs
- +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorEngineDocumentGenerator.cs
- @@ -27,9 +27,10 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
- }
- catch (Exception exception)
- {
- - throw new RazorLanguageServiceException(
- - typeof(DefaultRazorEngineDocumentGenerator).FullName,
- - nameof(GenerateDocumentAsync),
- + throw new InvalidOperationException(
- + Resources.FormatUnexpectedException(
- + typeof(DefaultRazorEngineDocumentGenerator).FullName,
- + nameof(GenerateDocumentAsync)),
- exception);
- }
- }
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs
- index 5ed80730d77..31713fb3b25 100644
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs
- +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs
- @@ -74,9 +74,10 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
- {
- _errorReporter.ReportError(exception, project);
-
- - throw new RazorLanguageServiceException(
- - typeof(DefaultTagHelperResolver).FullName,
- - nameof(GetTagHelpersAsync),
- + throw new InvalidOperationException(
- + Resources.FormatUnexpectedException(
- + typeof(DefaultTagHelperResolver).FullName,
- + nameof(GetTagHelpersAsync)),
- exception);
- }
- }
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AcceptedCharacters.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AcceptedCharacters.cs
- deleted file mode 100644
- index 034dda92983..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AcceptedCharacters.cs
- +++ /dev/null
- @@ -1,28 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - [Flags]
- - public enum AcceptedCharacters
- - {
- - None = 0,
- - NewLine = 1,
- - WhiteSpace = 2,
- -
- - NonWhiteSpace = 4,
- -
- - AllWhiteSpace = NewLine | WhiteSpace,
- - Any = AllWhiteSpace | NonWhiteSpace,
- -
- - AnyExceptNewline = NonWhiteSpace | WhiteSpace
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AttributeCompletionContext.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AttributeCompletionContext.cs
- deleted file mode 100644
- index f859c1d5c19..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AttributeCompletionContext.cs
- +++ /dev/null
- @@ -1,69 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public class AttributeCompletionContext
- - {
- - public AttributeCompletionContext(
- - TagHelperDocumentContext documentContext,
- - IEnumerable<string> existingCompletions,
- - string currentTagName,
- - IEnumerable<KeyValuePair<string, string>> attributes,
- - string currentParentTagName,
- - Func<string, bool> inHTMLSchema)
- - {
- - if (documentContext == null)
- - {
- - throw new ArgumentNullException(nameof(documentContext));
- - }
- -
- - if (existingCompletions == null)
- - {
- - throw new ArgumentNullException(nameof(existingCompletions));
- - }
- -
- - if (currentTagName == null)
- - {
- - throw new ArgumentNullException(nameof(currentTagName));
- - }
- -
- - if (attributes == null)
- - {
- - throw new ArgumentNullException(nameof(attributes));
- - }
- -
- - if (inHTMLSchema == null)
- - {
- - throw new ArgumentNullException(nameof(inHTMLSchema));
- - }
- -
- - DocumentContext = documentContext;
- - ExistingCompletions = existingCompletions;
- - CurrentTagName = currentTagName;
- - Attributes = attributes;
- - CurrentParentTagName = currentParentTagName;
- - InHTMLSchema = inHTMLSchema;
- - }
- -
- - public TagHelperDocumentContext DocumentContext { get; }
- -
- - public IEnumerable<string> ExistingCompletions { get; }
- -
- - public string CurrentTagName { get; }
- -
- - public IEnumerable<KeyValuePair<string, string>> Attributes { get; }
- -
- - public string CurrentParentTagName { get; }
- -
- - public Func<string, bool> InHTMLSchema { get; }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AttributeCompletionResult.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AttributeCompletionResult.cs
- deleted file mode 100644
- index 066d438054a..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/AttributeCompletionResult.cs
- +++ /dev/null
- @@ -1,45 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System.Collections.Generic;
- -using System.Linq;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public abstract class AttributeCompletionResult
- - {
- - private AttributeCompletionResult()
- - {
- - }
- -
- - public abstract IReadOnlyDictionary<string, IEnumerable<BoundAttributeDescriptor>> Completions { get; }
- -
- - internal static AttributeCompletionResult Create(Dictionary<string, HashSet<BoundAttributeDescriptor>> completions)
- - {
- - var readonlyCompletions = completions.ToDictionary(
- - key => key.Key,
- - value => (IEnumerable<BoundAttributeDescriptor>)value.Value,
- - completions.Comparer);
- - var result = new DefaultAttributeCompletionResult(readonlyCompletions);
- -
- - return result;
- - }
- -
- - private class DefaultAttributeCompletionResult : AttributeCompletionResult
- - {
- - private readonly IReadOnlyDictionary<string, IEnumerable<BoundAttributeDescriptor>> _completions;
- -
- - public DefaultAttributeCompletionResult(IReadOnlyDictionary<string, IEnumerable<BoundAttributeDescriptor>> completions)
- - {
- - _completions = completions;
- - }
- -
- - public override IReadOnlyDictionary<string, IEnumerable<BoundAttributeDescriptor>> Completions => _completions;
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/BlockKind.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/BlockKind.cs
- deleted file mode 100644
- index 5591b319437..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/BlockKind.cs
- +++ /dev/null
- @@ -1,28 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public enum BlockKind
- - {
- - // Code
- - Statement,
- - Directive,
- - Functions,
- - Expression,
- - Helper,
- -
- - // Markup
- - Markup,
- - Section,
- - Template,
- -
- - // Special
- - Comment,
- - Tag
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ClassifiedSpan.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ClassifiedSpan.cs
- deleted file mode 100644
- index a254d862dc3..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ClassifiedSpan.cs
- +++ /dev/null
- @@ -1,33 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public struct ClassifiedSpan
- - {
- - public ClassifiedSpan(SourceSpan span, SourceSpan blockSpan, SpanKind spanKind, BlockKind blockKind, AcceptedCharacters acceptedCharacters)
- - {
- - Span = span;
- - BlockSpan = blockSpan;
- - SpanKind = spanKind;
- - BlockKind = blockKind;
- - AcceptedCharacters = acceptedCharacters;
- - }
- -
- - public AcceptedCharacters AcceptedCharacters { get; }
- -
- - public BlockKind BlockKind { get; }
- -
- - public SourceSpan BlockSpan { get; }
- -
- - public SourceSpan Span { get; }
- -
- - public SpanKind SpanKind { get; }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultRazorSyntaxFactsService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultRazorSyntaxFactsService.cs
- deleted file mode 100644
- index 944942048bd..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultRazorSyntaxFactsService.cs
- +++ /dev/null
- @@ -1,352 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using System.ComponentModel.Composition;
- -using System.Linq;
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.AspNetCore.Razor.Language.Legacy;
- -using Microsoft.VisualStudio.Text;
- -using Span = Microsoft.AspNetCore.Razor.Language.Legacy.Span;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - [Export(typeof(RazorSyntaxFactsService))]
- - internal class DefaultRazorSyntaxFactsService : RazorSyntaxFactsService
- - {
- - public override IReadOnlyList<ClassifiedSpan> GetClassifiedSpans(RazorSyntaxTree syntaxTree)
- - {
- - if (syntaxTree == null)
- - {
- - throw new ArgumentNullException(nameof(syntaxTree));
- - }
- -
- - var spans = Flatten(syntaxTree);
- -
- - var result = new ClassifiedSpan[spans.Count];
- - for (var i = 0; i < spans.Count; i++)
- - {
- - var span = spans[i];
- - result[i] = new ClassifiedSpan(
- - new SourceSpan(
- - span.Start.FilePath ?? syntaxTree.Source.FilePath,
- - span.Start.AbsoluteIndex,
- - span.Start.LineIndex,
- - span.Start.CharacterIndex,
- - span.Length),
- - new SourceSpan(
- - span.Parent.Start.FilePath ?? syntaxTree.Source.FilePath,
- - span.Parent.Start.AbsoluteIndex,
- - span.Parent.Start.LineIndex,
- - span.Parent.Start.CharacterIndex,
- - span.Parent.Length),
- - (SpanKind)span.Kind,
- - (BlockKind)span.Parent.Type,
- - (AcceptedCharacters)span.EditHandler.AcceptedCharacters);
- - }
- -
- - return result;
- - }
- -
- - private List<Span> Flatten(RazorSyntaxTree syntaxTree)
- - {
- - var result = new List<Span>();
- - AppendFlattenedSpans(syntaxTree.Root, result);
- - return result;
- -
- - void AppendFlattenedSpans(SyntaxTreeNode node, List<Span> foundSpans)
- - {
- - Span spanNode = node as Span;
- - if (spanNode != null)
- - {
- - foundSpans.Add(spanNode);
- - }
- - else
- - {
- - TagHelperBlock tagHelperNode = node as TagHelperBlock;
- - if (tagHelperNode != null)
- - {
- - // These aren't in document order, sort them first and then dig in
- - List<SyntaxTreeNode> attributeNodes = tagHelperNode.Attributes.Select(kvp => kvp.Value).Where(att => att != null).ToList();
- - attributeNodes.Sort((x, y) => x.Start.AbsoluteIndex.CompareTo(y.Start.AbsoluteIndex));
- -
- - foreach (SyntaxTreeNode curNode in attributeNodes)
- - {
- - AppendFlattenedSpans(curNode, foundSpans);
- - }
- - }
- -
- - Block blockNode = node as Block;
- - if (blockNode != null)
- - {
- - foreach (SyntaxTreeNode curNode in blockNode.Children)
- - {
- - AppendFlattenedSpans(curNode, foundSpans);
- - }
- - }
- - }
- - }
- - }
- -
- - public override IReadOnlyList<TagHelperSpan> GetTagHelperSpans(RazorSyntaxTree syntaxTree)
- - {
- - if (syntaxTree == null)
- - {
- - throw new ArgumentNullException(nameof(syntaxTree));
- - }
- -
- - var results = new List<TagHelperSpan>();
- -
- - List<Block> toProcess = new List<Block>();
- - List<Block> blockChildren = new List<Block>();
- - toProcess.Add(syntaxTree.Root);
- -
- - for (var i = 0; i < toProcess.Count; i++)
- - {
- - var blockNode = toProcess[i];
- - TagHelperBlock tagHelperNode = blockNode as TagHelperBlock;
- - if (tagHelperNode != null)
- - {
- - results.Add(new TagHelperSpan(
- - new SourceSpan(
- - tagHelperNode.Start.FilePath ?? syntaxTree.Source.FilePath,
- - tagHelperNode.Start.AbsoluteIndex,
- - tagHelperNode.Start.LineIndex,
- - tagHelperNode.Start.CharacterIndex,
- - tagHelperNode.Length),
- - tagHelperNode.Binding));
- - }
- -
- - // collect all child blocks and inject into toProcess as a single InsertRange
- - foreach (SyntaxTreeNode curNode in blockNode.Children)
- - {
- - Block curBlock = curNode as Block;
- - if (curBlock != null)
- - {
- - blockChildren.Add(curBlock);
- - }
- - }
- -
- - if (blockChildren.Count > 0)
- - {
- - toProcess.InsertRange(i + 1, blockChildren);
- - blockChildren.Clear();
- - }
- - }
- -
- - return results;
- - }
- -
- - public override int? GetDesiredIndentation(RazorSyntaxTree syntaxTree, ITextSnapshot syntaxTreeSnapshot, ITextSnapshotLine line, int indentSize, int tabSize)
- - {
- - if (syntaxTree == null)
- - {
- - throw new ArgumentNullException(nameof(syntaxTree));
- - }
- -
- - if (syntaxTreeSnapshot == null)
- - {
- - throw new ArgumentNullException(nameof(syntaxTreeSnapshot));
- - }
- -
- - if (line == null)
- - {
- - throw new ArgumentNullException(nameof(line));
- - }
- -
- - if (indentSize < 0)
- - {
- - throw new ArgumentOutOfRangeException(nameof(indentSize));
- - }
- -
- - if (tabSize < 0)
- - {
- - throw new ArgumentOutOfRangeException(nameof(tabSize));
- - }
- -
- - // The tricky thing here is that line.Snapshot is very likely newer
- - var previousLine = line.Snapshot.GetLineFromLineNumber(line.LineNumber - 1);
- - var trackingPoint = line.Snapshot.CreateTrackingPoint(line.End, PointTrackingMode.Negative);
- - var previousLineEnd = trackingPoint.GetPosition(syntaxTreeSnapshot);
- -
- - var simulatedChange = new SourceChange(previousLineEnd, 0, string.Empty);
- - var owningSpan = LocateOwner(syntaxTree.Root, simulatedChange);
- -
- - int? desiredIndentation = null;
- -
- - if (owningSpan.Kind != SpanKindInternal.Code)
- - {
- - SyntaxTreeNode owningChild = owningSpan;
- - while ((owningChild.Parent != null) && !desiredIndentation.HasValue)
- - {
- - Block owningParent = owningChild.Parent;
- - List<SyntaxTreeNode> children = new List<SyntaxTreeNode>(owningParent.Children);
- - for (int i = 0; i < children.Count; i++)
- - {
- - SyntaxTreeNode curChild = children[i];
- - if (!curChild.IsBlock)
- - {
- - Span curSpan = curChild as Span;
- - if (curSpan.Kind == SpanKindInternal.MetaCode)
- - {
- - // yay! We want to use the start of this span to determine the indent level.
- - var startLine = line.Snapshot.GetLineFromLineNumber(curSpan.Start.LineIndex);
- - var extraIndent = 0;
- -
- - // Dev11 337312: Only indent one level deeper if the item after the metacode is a markup block
- - if (i < children.Count - 1)
- - {
- - SyntaxTreeNode nextChild = children[i + 1];
- - if (nextChild.IsBlock && ((nextChild as Block).Type == BlockKindInternal.Markup))
- - {
- - extraIndent = indentSize;
- - }
- - }
- -
- - desiredIndentation = GetIndentLevelOfLine(startLine, tabSize) + indentSize;
- - }
- - }
- -
- - if (curChild == owningChild)
- - {
- - break;
- - }
- - }
- -
- - owningChild = owningParent;
- - }
- - }
- -
- - return desiredIndentation;
- - }
- -
- - private Span LocateOwner(Block root, SourceChange change)
- - {
- - // Ask each child recursively
- - Span owner = null;
- - foreach (SyntaxTreeNode element in root.Children)
- - {
- - if (element.Start.AbsoluteIndex > change.Span.AbsoluteIndex)
- - {
- - // too far
- - break;
- - }
- -
- - int elementLen = element.Length;
- - if (element.Start.AbsoluteIndex + elementLen < change.Span.AbsoluteIndex)
- - {
- - // not far enough
- - continue;
- - }
- -
- - if (element.IsBlock)
- - {
- - Block block = element as Block;
- -
- - if (element.Start.AbsoluteIndex + elementLen == change.Span.AbsoluteIndex)
- - {
- - Span lastDescendant = block.FindLastDescendentSpan();
- - if ((lastDescendant == null) && (block is TagHelperBlock))
- - {
- - TagHelperBlock tagHelperBlock = (TagHelperBlock)block;
- - if (tagHelperBlock.SourceEndTag != null)
- - {
- - lastDescendant = tagHelperBlock.SourceEndTag.FindLastDescendentSpan();
- - }
- - else if (tagHelperBlock.SourceStartTag != null)
- - {
- - lastDescendant = tagHelperBlock.SourceStartTag.FindLastDescendentSpan();
- - }
- - }
- -
- - // Conceptually, lastDescendant should always be non-null, but runtime errs on some
- - // cases and makes empty blocks. Runtime will fix these issues as we find them, but make
- - // no guarantee that they catch them all.
- - if (lastDescendant == null)
- - {
- - owner = LocateOwner(block, change);
- - if (owner != null)
- - {
- - break;
- - }
- - }
- - else if (lastDescendant.EditHandler.OwnsChange(lastDescendant, change))
- - {
- - owner = lastDescendant;
- - break;
- - }
- - }
- - else
- - {
- - owner = LocateOwner(block, change);
- - if (owner != null)
- - {
- - break;
- - }
- - }
- - }
- - else
- - {
- - Span span = element as Span;
- - if (span.EditHandler.OwnsChange(span, change))
- - {
- - owner = span;
- - break;
- - }
- - }
- - }
- -
- - if (owner == null)
- - {
- - TagHelperBlock tagHelperNode = root as TagHelperBlock;
- - if (tagHelperNode != null)
- - {
- - Block sourceStartTag = tagHelperNode.SourceStartTag;
- - Block sourceEndTag = tagHelperNode.SourceEndTag;
- - if ((sourceStartTag.Start.AbsoluteIndex <= change.Span.AbsoluteIndex) &&
- - (sourceStartTag.Start.AbsoluteIndex + sourceStartTag.Length >= change.Span.AbsoluteIndex))
- - {
- - // intersects the start tag
- - return LocateOwner(sourceStartTag, change);
- - }
- - else if ((sourceEndTag.Start.AbsoluteIndex <= change.Span.AbsoluteIndex) &&
- - (sourceEndTag.Start.AbsoluteIndex + sourceEndTag.Length >= change.Span.AbsoluteIndex))
- - {
- - // intersects the end tag
- - return LocateOwner(sourceEndTag, change);
- - }
- - }
- - }
- -
- - return owner;
- - }
- -
- - private int GetIndentLevelOfLine(ITextSnapshotLine line, int tabSize)
- - {
- - var indentLevel = 0;
- -
- - foreach (var c in line.GetText())
- - {
- - if (!char.IsWhiteSpace(c))
- - {
- - break;
- - }
- - else if (c == '\t')
- - {
- - indentLevel += tabSize;
- - }
- - else
- - {
- - indentLevel++;
- - }
- - }
- -
- - return indentLevel;
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultTagHelperCompletionService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultTagHelperCompletionService.cs
- deleted file mode 100644
- index e81e01ccce5..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultTagHelperCompletionService.cs
- +++ /dev/null
- @@ -1,285 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using System.ComponentModel.Composition;
- -using System.Diagnostics;
- -using System.Linq;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - [Export(typeof(TagHelperCompletionService))]
- - internal class DefaultTagHelperCompletionService : TagHelperCompletionService
- - {
- - private readonly TagHelperFactsService _tagHelperFactsService;
- - private static readonly HashSet<TagHelperDescriptor> _emptyHashSet = new HashSet<TagHelperDescriptor>();
- -
- - [ImportingConstructor]
- - public DefaultTagHelperCompletionService(TagHelperFactsService tagHelperFactsService)
- - {
- - _tagHelperFactsService = tagHelperFactsService;
- - }
- -
- - /*
- - * This API attempts to understand a users context as they're typing in a Razor file to provide TagHelper based attribute IntelliSense.
- - *
- - * Scenarios for TagHelper attribute IntelliSense follows:
- - * 1. TagHelperDescriptor's have matching required attribute names
- - * -> Provide IntelliSense for the required attributes of those descriptors to lead users towards a TagHelperified element.
- - * 2. TagHelperDescriptor entirely applies to current element. Tag name, attributes, everything is fulfilled.
- - * -> Provide IntelliSense for the bound attributes for the applied descriptors.
- - *
- - * Within each of the above scenarios if an attribute completion has a corresponding bound attribute we associate it with the corresponding
- - * BoundAttributeDescriptor. By doing this a user can see what C# type a TagHelper expects for the attribute.
- - */
- - public override AttributeCompletionResult GetAttributeCompletions(AttributeCompletionContext completionContext)
- - {
- - if (completionContext == null)
- - {
- - throw new ArgumentNullException(nameof(completionContext));
- - }
- -
- - var attributeCompletions = completionContext.ExistingCompletions.ToDictionary(
- - completion => completion,
- - _ => new HashSet<BoundAttributeDescriptor>(),
- - StringComparer.OrdinalIgnoreCase);
- -
- - var documentContext = completionContext.DocumentContext;
- - var descriptorsForTag = _tagHelperFactsService.GetTagHelpersGivenTag(documentContext, completionContext.CurrentTagName, completionContext.CurrentParentTagName);
- - if (descriptorsForTag.Count == 0)
- - {
- - // If the current tag has no possible descriptors then we can't have any additional attributes.
- - var defaultResult = AttributeCompletionResult.Create(attributeCompletions);
- - return defaultResult;
- - }
- -
- - var prefix = documentContext.Prefix ?? string.Empty;
- - Debug.Assert(completionContext.CurrentTagName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
- -
- - var applicableTagHelperBinding = _tagHelperFactsService.GetTagHelperBinding(
- - documentContext,
- - completionContext.CurrentTagName,
- - completionContext.Attributes,
- - completionContext.CurrentParentTagName);
- -
- - var applicableDescriptors = applicableTagHelperBinding?.Descriptors ?? Enumerable.Empty<TagHelperDescriptor>();
- - var unprefixedTagName = completionContext.CurrentTagName.Substring(prefix.Length);
- -
- - if (!completionContext.InHTMLSchema(unprefixedTagName) &&
- - applicableDescriptors.All(descriptor => descriptor.TagOutputHint == null))
- - {
- - // This isn't a known HTML tag and no descriptor has an output element hint. Remove all previous completions.
- - attributeCompletions.Clear();
- - }
- -
- - for (var i = 0; i < descriptorsForTag.Count; i++)
- - {
- - var descriptor = descriptorsForTag[i];
- -
- - if (applicableDescriptors.Contains(descriptor))
- - {
- - foreach (var attributeDescriptor in descriptor.BoundAttributes)
- - {
- - UpdateCompletions(attributeDescriptor.Name, attributeDescriptor);
- - }
- - }
- - else
- - {
- - var htmlNameToBoundAttribute = descriptor.BoundAttributes.ToDictionary(attribute => attribute.Name, StringComparer.OrdinalIgnoreCase);
- -
- - foreach (var rule in descriptor.TagMatchingRules)
- - {
- - foreach (var requiredAttribute in rule.Attributes)
- - {
- - if (htmlNameToBoundAttribute.TryGetValue(requiredAttribute.Name, out var attributeDescriptor))
- - {
- - UpdateCompletions(requiredAttribute.Name, attributeDescriptor);
- - }
- - else
- - {
- - UpdateCompletions(requiredAttribute.Name, possibleDescriptor: null);
- - }
- - }
- - }
- - }
- - }
- -
- - var completionResult = AttributeCompletionResult.Create(attributeCompletions);
- - return completionResult;
- -
- - void UpdateCompletions(string attributeName, BoundAttributeDescriptor possibleDescriptor)
- - {
- - if (completionContext.Attributes.Any(attribute => string.Equals(attribute.Key, attributeName, StringComparison.OrdinalIgnoreCase)))
- - {
- - // Attribute is already present on this element it shouldn't exist in the completion list.
- - return;
- - }
- -
- - if (!attributeCompletions.TryGetValue(attributeName, out var rules))
- - {
- - rules = new HashSet<BoundAttributeDescriptor>();
- - attributeCompletions[attributeName] = rules;
- - }
- -
- - if (possibleDescriptor != null)
- - {
- - rules.Add(possibleDescriptor);
- - }
- - }
- - }
- -
- - public override ElementCompletionResult GetElementCompletions(ElementCompletionContext completionContext)
- - {
- - if (completionContext == null)
- - {
- - throw new ArgumentNullException(nameof(completionContext));
- - }
- -
- - var elementCompletions = new Dictionary<string, HashSet<TagHelperDescriptor>>(StringComparer.OrdinalIgnoreCase);
- -
- - AddAllowedChildrenCompletions(completionContext, elementCompletions);
- -
- - if (elementCompletions.Count > 0)
- - {
- - // If the containing element is already a TagHelper and only allows certain children.
- - var emptyResult = ElementCompletionResult.Create(elementCompletions);
- - return emptyResult;
- - }
- -
- - elementCompletions = completionContext.ExistingCompletions.ToDictionary(
- - completion => completion,
- - _ => new HashSet<TagHelperDescriptor>(),
- - StringComparer.OrdinalIgnoreCase);
- -
- - var catchAllDescriptors = new HashSet<TagHelperDescriptor>();
- - var prefix = completionContext.DocumentContext.Prefix ?? string.Empty;
- - var possibleChildDescriptors = _tagHelperFactsService.GetTagHelpersGivenParent(completionContext.DocumentContext, completionContext.ContainingTagName);
- - foreach (var possibleDescriptor in possibleChildDescriptors)
- - {
- - var addRuleCompletions = false;
- - var outputHint = possibleDescriptor.TagOutputHint;
- -
- - foreach (var rule in possibleDescriptor.TagMatchingRules)
- - {
- - if (rule.TagName == TagHelperMatchingConventions.ElementCatchAllName)
- - {
- - catchAllDescriptors.Add(possibleDescriptor);
- - }
- - else if (elementCompletions.ContainsKey(rule.TagName))
- - {
- - addRuleCompletions = true;
- - }
- - else if (outputHint != null)
- - {
- - // If the current descriptor has an output hint we need to make sure it shows up only when its output hint would normally show up.
- - // Example: We have a MyTableTagHelper that has an output hint of "table" and a MyTrTagHelper that has an output hint of "tr".
- - // If we try typing in a situation like this: <body > | </body>
- - // We'd expect to only get "my-table" as a completion because the "body" tag doesn't allow "tr" tags.
- - addRuleCompletions = elementCompletions.ContainsKey(outputHint);
- - }
- - else if (!completionContext.InHTMLSchema(rule.TagName))
- - {
- - // If there is an unknown HTML schema tag that doesn't exist in the current completion we should add it. This happens for
- - // TagHelpers that target non-schema oriented tags.
- - addRuleCompletions = true;
- - }
- -
- - if (addRuleCompletions)
- - {
- - UpdateCompletions(prefix + rule.TagName, possibleDescriptor);
- - }
- - }
- - }
- -
- - // We needed to track all catch-alls and update their completions after all other completions have been completed.
- - // This way, any TagHelper added completions will also have catch-alls listed under their entries.
- - foreach (var catchAllDescriptor in catchAllDescriptors)
- - {
- - foreach (var completionTagName in elementCompletions.Keys)
- - {
- - if (elementCompletions[completionTagName].Count > 0 ||
- - !string.IsNullOrEmpty(prefix) && completionTagName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
- - {
- - // The current completion either has other TagHelper's associated with it or is prefixed with a non-empty
- - // TagHelper prefix.
- - UpdateCompletions(completionTagName, catchAllDescriptor);
- - }
- - }
- - }
- -
- - var result = ElementCompletionResult.Create(elementCompletions);
- - return result;
- -
- - void UpdateCompletions(string tagName, TagHelperDescriptor possibleDescriptor)
- - {
- - if (!elementCompletions.TryGetValue(tagName, out var existingRuleDescriptors))
- - {
- - existingRuleDescriptors = new HashSet<TagHelperDescriptor>();
- - elementCompletions[tagName] = existingRuleDescriptors;
- - }
- -
- - existingRuleDescriptors.Add(possibleDescriptor);
- - }
- - }
- -
- - private void AddAllowedChildrenCompletions(
- - ElementCompletionContext completionContext,
- - Dictionary<string, HashSet<TagHelperDescriptor>> elementCompletions)
- - {
- - if (completionContext.ContainingTagName == null)
- - {
- - // If we're at the root then there's no containing TagHelper to specify allowed children.
- - return;
- - }
- -
- - var prefix = completionContext.DocumentContext.Prefix ?? string.Empty;
- - var binding = _tagHelperFactsService.GetTagHelperBinding(
- - completionContext.DocumentContext,
- - completionContext.ContainingTagName,
- - completionContext.Attributes,
- - completionContext.ContainingParentTagName);
- -
- - if (binding == null)
- - {
- - // Containing tag is not a TagHelper; therefore, it allows any children.
- - return;
- - }
- -
- - foreach (var descriptor in binding.Descriptors)
- - {
- - foreach (var childTag in descriptor.AllowedChildTags)
- - {
- - var prefixedName = string.Concat(prefix, childTag.Name);
- - var descriptors = _tagHelperFactsService.GetTagHelpersGivenTag(
- - completionContext.DocumentContext,
- - prefixedName,
- - completionContext.ContainingTagName);
- -
- - if (descriptors.Count == 0)
- - {
- - if (!elementCompletions.ContainsKey(prefixedName))
- - {
- - elementCompletions[prefixedName] = _emptyHashSet;
- - }
- -
- - continue;
- - }
- -
- - if (!elementCompletions.TryGetValue(prefixedName, out var existingRuleDescriptors))
- - {
- - existingRuleDescriptors = new HashSet<TagHelperDescriptor>();
- - elementCompletions[prefixedName] = existingRuleDescriptors;
- - }
- -
- - existingRuleDescriptors.UnionWith(descriptors);
- - }
- - }
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultTagHelperFactsService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultTagHelperFactsService.cs
- deleted file mode 100644
- index 8e0b34b431c..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DefaultTagHelperFactsService.cs
- +++ /dev/null
- @@ -1,168 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using System.ComponentModel.Composition;
- -using System.Linq;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - [Export(typeof(TagHelperFactsService))]
- - internal class DefaultTagHelperFactsService : TagHelperFactsService
- - {
- - public override TagHelperBinding GetTagHelperBinding(
- - TagHelperDocumentContext documentContext,
- - string tagName,
- - IEnumerable<KeyValuePair<string, string>> attributes,
- - string parentTag)
- - {
- - if (documentContext == null)
- - {
- - throw new ArgumentNullException(nameof(documentContext));
- - }
- -
- - if (tagName == null)
- - {
- - throw new ArgumentNullException(nameof(tagName));
- - }
- -
- - if (attributes == null)
- - {
- - throw new ArgumentNullException(nameof(attributes));
- - }
- -
- - var descriptors = documentContext.TagHelpers;
- - if (descriptors == null || descriptors.Count == 0)
- - {
- - return null;
- - }
- -
- - var prefix = documentContext.Prefix;
- - var tagHelperBinder = new TagHelperBinder(prefix, descriptors);
- - var binding = tagHelperBinder.GetBinding(tagName, attributes.ToList(), parentTag, parentIsTagHelper: false);
- -
- - return binding;
- - }
- -
- - public override IEnumerable<BoundAttributeDescriptor> GetBoundTagHelperAttributes(
- - TagHelperDocumentContext documentContext,
- - string attributeName,
- - TagHelperBinding binding)
- - {
- - if (documentContext == null)
- - {
- - throw new ArgumentNullException(nameof(documentContext));
- - }
- -
- - if (attributeName == null)
- - {
- - throw new ArgumentNullException(nameof(attributeName));
- - }
- -
- - if (binding == null)
- - {
- - throw new ArgumentNullException(nameof(binding));
- - }
- -
- - var matchingBoundAttributes = new List<BoundAttributeDescriptor>();
- - foreach (var descriptor in binding.Descriptors)
- - {
- - foreach (var boundAttributeDescriptor in descriptor.BoundAttributes)
- - {
- - if (TagHelperMatchingConventions.CanSatisfyBoundAttribute(attributeName, boundAttributeDescriptor))
- - {
- - matchingBoundAttributes.Add(boundAttributeDescriptor);
- -
- - // Only one bound attribute can match an attribute
- - break;
- - }
- - }
- - }
- -
- - return matchingBoundAttributes;
- - }
- -
- - public override IReadOnlyList<TagHelperDescriptor> GetTagHelpersGivenTag(
- - TagHelperDocumentContext documentContext,
- - string tagName,
- - string parentTag)
- - {
- - if (documentContext == null)
- - {
- - throw new ArgumentNullException(nameof(documentContext));
- - }
- -
- - if (tagName == null)
- - {
- - throw new ArgumentNullException(nameof(tagName));
- - }
- -
- - var matchingDescriptors = new List<TagHelperDescriptor>();
- - var descriptors = documentContext?.TagHelpers;
- - if (descriptors?.Count == 0)
- - {
- - return matchingDescriptors;
- - }
- -
- - var prefix = documentContext.Prefix ?? string.Empty;
- - if (!tagName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
- - {
- - // Can't possibly match TagHelpers, it doesn't start with the TagHelperPrefix.
- - return matchingDescriptors;
- - }
- -
- - var tagNameWithoutPrefix = tagName.Substring(prefix.Length);
- - for (var i = 0; i < descriptors.Count; i++)
- - {
- - var descriptor = descriptors[i];
- - foreach (var rule in descriptor.TagMatchingRules)
- - {
- - if (TagHelperMatchingConventions.SatisfiesTagName(tagNameWithoutPrefix, rule) &&
- - TagHelperMatchingConventions.SatisfiesParentTag(parentTag, rule))
- - {
- - matchingDescriptors.Add(descriptor);
- - break;
- - }
- - }
- - }
- -
- - return matchingDescriptors;
- - }
- -
- - public override IReadOnlyList<TagHelperDescriptor> GetTagHelpersGivenParent(TagHelperDocumentContext documentContext, string parentTag)
- - {
- - if (documentContext == null)
- - {
- - throw new ArgumentNullException(nameof(documentContext));
- - }
- -
- - var matchingDescriptors = new List<TagHelperDescriptor>();
- - var descriptors = documentContext?.TagHelpers;
- - if (descriptors?.Count == 0)
- - {
- - return matchingDescriptors;
- - }
- -
- - for (var i = 0; i < descriptors.Count; i++)
- - {
- - var descriptor = descriptors[i];
- - foreach (var rule in descriptor.TagMatchingRules)
- - {
- - if (TagHelperMatchingConventions.SatisfiesParentTag(parentTag, rule))
- - {
- - matchingDescriptors.Add(descriptor);
- - break;
- - }
- - }
- - }
- -
- - return matchingDescriptors;
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DocumentParseCompleteEventArgs.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DocumentParseCompleteEventArgs.cs
- deleted file mode 100644
- index c8dc5065c8e..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/DocumentParseCompleteEventArgs.cs
- +++ /dev/null
- @@ -1,47 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.VisualStudio.Text;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - /// <summary>
- - /// Arguments for the <see cref="RazorEditorParser.DocumentParseComplete"/> event in <see cref="RazorEditorParser"/>.
- - /// </summary>
- - public sealed class DocumentParseCompleteEventArgs : EventArgs
- - {
- - public DocumentParseCompleteEventArgs(
- - SourceChange change,
- - ITextSnapshot buffer,
- - bool treeStructureChanged,
- - RazorCodeDocument codeDocument)
- - {
- - SourceChange = change;
- - Buffer = buffer;
- - TreeStructureChanged = treeStructureChanged;
- - CodeDocument = codeDocument;
- - }
- -
- - /// <summary>
- - /// The <see cref="AspNetCore.Razor.Language.SourceChange"/> which triggered the re-parse.
- - /// </summary>
- - public SourceChange SourceChange { get; }
- -
- - /// <summary>
- - /// The text snapshot used in the re-parse.
- - /// </summary>
- - public ITextSnapshot Buffer { get; }
- -
- - /// <summary>
- - /// Indicates if the tree structure has actually changed since the previous re-parse.
- - /// </summary>
- - public bool TreeStructureChanged { get; }
- -
- - /// <summary>
- - /// The result of the parsing and code generation.
- - /// </summary>
- - public RazorCodeDocument CodeDocument { get; }
- - }
- -}
- \ No newline at end of file
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ElementCompletionContext.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ElementCompletionContext.cs
- deleted file mode 100644
- index c38c8485c71..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ElementCompletionContext.cs
- +++ /dev/null
- @@ -1,59 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public sealed class ElementCompletionContext
- - {
- - public ElementCompletionContext(
- - TagHelperDocumentContext documentContext,
- - IEnumerable<string> existingCompletions,
- - string containingTagName,
- - IEnumerable<KeyValuePair<string, string>> attributes,
- - string containingParentTagName,
- - Func<string, bool> inHTMLSchema)
- - {
- - if (documentContext == null)
- - {
- - throw new ArgumentNullException(nameof(documentContext));
- - }
- -
- - if (existingCompletions == null)
- - {
- - throw new ArgumentNullException(nameof(existingCompletions));
- - }
- -
- - if (inHTMLSchema == null)
- - {
- - throw new ArgumentNullException(nameof(inHTMLSchema));
- - }
- -
- - DocumentContext = documentContext;
- - ExistingCompletions = existingCompletions;
- - ContainingTagName = containingTagName;
- - Attributes = attributes;
- - ContainingParentTagName = containingParentTagName;
- - InHTMLSchema = inHTMLSchema;
- - }
- -
- - public TagHelperDocumentContext DocumentContext { get; }
- -
- - public IEnumerable<string> ExistingCompletions { get; }
- -
- - public string ContainingTagName { get; }
- -
- - public IEnumerable<KeyValuePair<string, string>> Attributes { get; }
- -
- - public string ContainingParentTagName { get; }
- -
- - public Func<string, bool> InHTMLSchema { get; }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ElementCompletionResult.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ElementCompletionResult.cs
- deleted file mode 100644
- index 88dc0c6a56f..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ElementCompletionResult.cs
- +++ /dev/null
- @@ -1,45 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System.Collections.Generic;
- -using System.Linq;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public abstract class ElementCompletionResult
- - {
- - private ElementCompletionResult()
- - {
- - }
- -
- - public abstract IReadOnlyDictionary<string, IEnumerable<TagHelperDescriptor>> Completions { get; }
- -
- - internal static ElementCompletionResult Create(Dictionary<string, HashSet<TagHelperDescriptor>> completions)
- - {
- - var readonlyCompletions = completions.ToDictionary(
- - key => key.Key,
- - value => (IEnumerable<TagHelperDescriptor>)value.Value,
- - completions.Comparer);
- - var result = new DefaultElementCompletionResult(readonlyCompletions);
- -
- - return result;
- - }
- -
- - private class DefaultElementCompletionResult : ElementCompletionResult
- - {
- - private readonly IReadOnlyDictionary<string, IEnumerable<TagHelperDescriptor>> _completions;
- -
- - public DefaultElementCompletionResult(IReadOnlyDictionary<string, IEnumerable<TagHelperDescriptor>> completions)
- - {
- - _completions = completions;
- - }
- -
- - public override IReadOnlyDictionary<string, IEnumerable<TagHelperDescriptor>> Completions => _completions;
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ITagHelperResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ITagHelperResolver.cs
- deleted file mode 100644
- index 80c25027148..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ITagHelperResolver.cs
- +++ /dev/null
- @@ -1,18 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System.Threading.Tasks;
- -using Microsoft.CodeAnalysis;
- -using Microsoft.CodeAnalysis.Razor;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public interface ITagHelperResolver
- - {
- - Task<TagHelperResolutionResult> GetTagHelpersAsync(Project project);
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTagHelperResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTagHelperResolver.cs
- deleted file mode 100644
- index a646026ba1b..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTagHelperResolver.cs
- +++ /dev/null
- @@ -1,24 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System.ComponentModel.Composition;
- -using Microsoft.CodeAnalysis;
- -using Microsoft.CodeAnalysis.Razor;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use TagHelperResolver.
- - // ----------------------------------------------------------------------------------------------------
- - [Export(typeof(ITagHelperResolver))]
- - internal class LegacyTagHelperResolver : DefaultTagHelperResolver, ITagHelperResolver
- - {
- - [ImportingConstructor]
- - public LegacyTagHelperResolver(
- - [Import(typeof(VisualStudioWorkspace))] Workspace workspace)
- - : base(workspace.Services.GetRequiredService<ErrorReporter>(), workspace)
- - {
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTemplateEngineFactoryService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTemplateEngineFactoryService.cs
- deleted file mode 100644
- index fcae83b4eca..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTemplateEngineFactoryService.cs
- +++ /dev/null
- @@ -1,62 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.ComponentModel.Composition;
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.CodeAnalysis;
- -using Microsoft.CodeAnalysis.Razor;
- -using Inner = Microsoft.CodeAnalysis.Razor.RazorTemplateEngineFactoryService;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use DefaultTemplateEngineFactoryService.
- - // ----------------------------------------------------------------------------------------------------
- - [Export(typeof(RazorTemplateEngineFactoryService))]
- - internal class LegacyTemplateEngineFactoryService : RazorTemplateEngineFactoryService
- - {
- - private readonly Inner _inner;
- - private readonly Workspace _workspace;
- -
- - [ImportingConstructor]
- - public LegacyTemplateEngineFactoryService([Import(typeof(VisualStudioWorkspace))] Workspace workspace)
- - {
- - if (workspace == null)
- - {
- - throw new ArgumentNullException(nameof(workspace));
- - }
- -
- - _workspace = workspace;
- - _inner = workspace.Services.GetLanguageServices(RazorLanguage.Name).GetRequiredService<Inner>();
- - }
- -
- - // internal for testing
- - internal LegacyTemplateEngineFactoryService(Workspace workspace, Inner inner)
- - {
- - if (workspace == null)
- - {
- - throw new ArgumentNullException(nameof(workspace));
- - }
- -
- - if (inner == null)
- - {
- - throw new ArgumentNullException(nameof(inner));
- - }
- -
- - _workspace = workspace;
- - _inner = inner;
- - }
- -
- - public override RazorTemplateEngine Create(string projectPath, Action<IRazorEngineBuilder> configure)
- - {
- - if (projectPath == null)
- - {
- - throw new ArgumentNullException(nameof(projectPath));
- - }
- -
- - return _inner.Create(projectPath, configure);
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTextBufferCodeDocumentProvider.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTextBufferCodeDocumentProvider.cs
- deleted file mode 100644
- index 963dfc9fe84..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTextBufferCodeDocumentProvider.cs
- +++ /dev/null
- @@ -1,40 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.ComponentModel.Composition;
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.VisualStudio.Editor.Razor;
- -using Microsoft.VisualStudio.Text;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
- -{
- - [System.Composition.Shared]
- - [Export(typeof(TextBufferCodeDocumentProvider))]
- - internal class LegacyTextBufferCodeDocumentProvider : TextBufferCodeDocumentProvider
- - {
- - public override bool TryGetFromBuffer(ITextBuffer textBuffer, out RazorCodeDocument codeDocument)
- - {
- - if (textBuffer == null)
- - {
- - throw new ArgumentNullException(nameof(textBuffer));
- - }
- -
- - if (textBuffer.Properties.TryGetProperty(typeof(VisualStudioRazorParser), out VisualStudioRazorParser parser) && parser.CodeDocument != null)
- - {
- - codeDocument = parser.CodeDocument;
- - return true;
- - }
- -
- - // Support the legacy parser for code document extraction.
- - if (textBuffer.Properties.TryGetProperty(typeof(RazorEditorParser), out RazorEditorParser legacyParser) && legacyParser.CodeDocument != null)
- - {
- - codeDocument = legacyParser.CodeDocument;
- - return true;
- - }
- -
- - codeDocument = null;
- - return false;
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/PartialParseResult.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/PartialParseResult.cs
- deleted file mode 100644
- index 2571342f690..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/PartialParseResult.cs
- +++ /dev/null
- @@ -1,21 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - [Flags]
- - public enum PartialParseResult
- - {
- - Rejected = 1,
- -
- - Accepted = 2,
- -
- - Provisional = 4,
- -
- - SpanContextChanged = 8,
- -
- - AutoCompleteBlock = 16
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorEditorParser.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorEditorParser.cs
- deleted file mode 100644
- index de7fbc9977f..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorEditorParser.cs
- +++ /dev/null
- @@ -1,623 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using System.Diagnostics;
- -using System.IO;
- -using System.Linq;
- -using System.Threading;
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.AspNetCore.Razor.Language.Legacy;
- -using Microsoft.VisualStudio.Editor.Razor;
- -using Microsoft.VisualStudio.Text;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - public class RazorEditorParser : IDisposable
- - {
- - private RazorTemplateEngine _templateEngine;
- -
- - private AspNetCore.Razor.Language.Legacy.Span _lastChangeOwner;
- - private AspNetCore.Razor.Language.Legacy.Span _lastAutoCompleteSpan;
- - private BackgroundParser _parser;
- -
- - // For testing only.
- - internal RazorEditorParser(RazorCodeDocument codeDocument)
- - {
- - CodeDocument = codeDocument;
- - }
- -
- - public RazorEditorParser(RazorTemplateEngine templateEngine, string filePath)
- - {
- - if (templateEngine == null)
- - {
- - throw new ArgumentNullException(nameof(templateEngine));
- - }
- -
- - if (string.IsNullOrEmpty(filePath))
- - {
- - throw new ArgumentException(
- - AspNetCore.Razor.Language.Resources.ArgumentCannotBeNullOrEmpty,
- - nameof(filePath));
- - }
- -
- - TemplateEngine = templateEngine;
- - FilePath = filePath;
- - _parser = new BackgroundParser(this, filePath);
- - _parser.ResultsReady += (sender, args) => OnDocumentParseComplete(args);
- - _parser.Start();
- - }
- -
- - /// <summary>
- - /// Event fired when a full reparse of the document completes.
- - /// </summary>
- - public event EventHandler<DocumentParseCompleteEventArgs> DocumentParseComplete;
- -
- - public RazorTemplateEngine TemplateEngine
- - {
- - get => _templateEngine;
- - set
- - {
- - if (value == null)
- - {
- - throw new ArgumentNullException(nameof(value));
- - }
- -
- - _templateEngine = value;
- - }
- - }
- -
- - public string FilePath { get; }
- -
- - // Internal for testing.
- - internal RazorSyntaxTree CurrentSyntaxTree { get; private set; }
- -
- - internal RazorCodeDocument CodeDocument { get; private set; }
- -
- - // Internal for testing.
- - internal bool LastResultProvisional { get; private set; }
- -
- - public virtual string GetAutoCompleteString()
- - {
- - if (_lastAutoCompleteSpan?.EditHandler is AutoCompleteEditHandler editHandler)
- - {
- - return editHandler.AutoCompleteString;
- - }
- -
- - return null;
- - }
- -
- - public virtual PartialParseResult CheckForStructureChanges(SourceChange change, ITextSnapshot snapshot)
- - {
- - if (snapshot == null)
- - {
- - throw new ArgumentNullException(nameof(snapshot));
- - }
- -
- - var result = PartialParseResultInternal.Rejected;
- -
- - using (_parser.SynchronizeMainThreadState())
- - {
- - // Check if we can partial-parse
- - if (CurrentSyntaxTree != null && _parser.IsIdle)
- - {
- - result = TryPartialParse(change);
- - }
- - }
- -
- - // If partial parsing failed or there were outstanding parser tasks, start a full reparse
- - if ((result & PartialParseResultInternal.Rejected) == PartialParseResultInternal.Rejected)
- - {
- - _parser.QueueChange(change, snapshot);
- - }
- -
- - // Otherwise, remember if this was provisionally accepted for next partial parse
- - LastResultProvisional = (result & PartialParseResultInternal.Provisional) == PartialParseResultInternal.Provisional;
- - VerifyFlagsAreValid(result);
- -
- - return (PartialParseResult)result;
- - }
- -
- - /// <summary>
- - /// Disposes of this parser. Should be called when the editor window is closed and the document is unloaded.
- - /// </summary>
- - public void Dispose()
- - {
- - _parser.Dispose();
- - GC.SuppressFinalize(this);
- - }
- -
- - private PartialParseResultInternal TryPartialParse(SourceChange change)
- - {
- - var result = PartialParseResultInternal.Rejected;
- -
- - // Try the last change owner
- - if (_lastChangeOwner != null && _lastChangeOwner.EditHandler.OwnsChange(_lastChangeOwner, change))
- - {
- - var editResult = _lastChangeOwner.EditHandler.ApplyChange(_lastChangeOwner, change);
- - result = editResult.Result;
- - if ((editResult.Result & PartialParseResultInternal.Rejected) != PartialParseResultInternal.Rejected)
- - {
- - _lastChangeOwner.ReplaceWith(editResult.EditedSpan);
- - }
- -
- - return result;
- - }
- -
- - // Locate the span responsible for this change
- - _lastChangeOwner = CurrentSyntaxTree.Root.LocateOwner(change);
- -
- - if (LastResultProvisional)
- - {
- - // Last change owner couldn't accept this, so we must do a full reparse
- - result = PartialParseResultInternal.Rejected;
- - }
- - else if (_lastChangeOwner != null)
- - {
- - var editResult = _lastChangeOwner.EditHandler.ApplyChange(_lastChangeOwner, change);
- - result = editResult.Result;
- - if ((editResult.Result & PartialParseResultInternal.Rejected) != PartialParseResultInternal.Rejected)
- - {
- - _lastChangeOwner.ReplaceWith(editResult.EditedSpan);
- - }
- - if ((result & PartialParseResultInternal.AutoCompleteBlock) == PartialParseResultInternal.AutoCompleteBlock)
- - {
- - _lastAutoCompleteSpan = _lastChangeOwner;
- - }
- - else
- - {
- - _lastAutoCompleteSpan = null;
- - }
- - }
- -
- - return result;
- - }
- -
- - private void OnDocumentParseComplete(DocumentParseCompleteEventArgs args)
- - {
- - using (_parser.SynchronizeMainThreadState())
- - {
- - CurrentSyntaxTree = args.CodeDocument.GetSyntaxTree();
- - CodeDocument = args.CodeDocument;
- - _lastChangeOwner = null;
- - }
- -
- - Debug.Assert(args != null, "Event arguments cannot be null");
- - EventHandler<DocumentParseCompleteEventArgs> handler = DocumentParseComplete;
- - if (handler != null)
- - {
- - try
- - {
- - handler(this, args);
- - }
- - catch (Exception ex)
- - {
- - Debug.WriteLine("[RzEd] Document Parse Complete Handler Threw: " + ex.ToString());
- - }
- - }
- - }
- -
- - [Conditional("DEBUG")]
- - private static void VerifyFlagsAreValid(PartialParseResultInternal result)
- - {
- - Debug.Assert(((result & PartialParseResultInternal.Accepted) == PartialParseResultInternal.Accepted) ||
- - ((result & PartialParseResultInternal.Rejected) == PartialParseResultInternal.Rejected),
- - "Partial Parse result does not have either of Accepted or Rejected flags set");
- - Debug.Assert(((result & PartialParseResultInternal.Rejected) == PartialParseResultInternal.Rejected) ||
- - ((result & PartialParseResultInternal.SpanContextChanged) != PartialParseResultInternal.SpanContextChanged),
- - "Partial Parse result was Accepted AND had SpanContextChanged flag set");
- - Debug.Assert(((result & PartialParseResultInternal.Rejected) == PartialParseResultInternal.Rejected) ||
- - ((result & PartialParseResultInternal.AutoCompleteBlock) != PartialParseResultInternal.AutoCompleteBlock),
- - "Partial Parse result was Accepted AND had AutoCompleteBlock flag set");
- - Debug.Assert(((result & PartialParseResultInternal.Accepted) == PartialParseResultInternal.Accepted) ||
- - ((result & PartialParseResultInternal.Provisional) != PartialParseResultInternal.Provisional),
- - "Partial Parse result was Rejected AND had Provisional flag set");
- - }
- -
- - internal class BackgroundParser : IDisposable
- - {
- - private MainThreadState _main;
- - private BackgroundThread _bg;
- -
- - public BackgroundParser(RazorEditorParser parser, string filePath)
- - {
- - _main = new MainThreadState(filePath);
- - _bg = new BackgroundThread(_main, parser, filePath);
- -
- - _main.ResultsReady += (sender, args) => OnResultsReady(args);
- - }
- -
- - /// <summary>
- - /// Fired on the main thread.
- - /// </summary>
- - public event EventHandler<DocumentParseCompleteEventArgs> ResultsReady;
- -
- - public bool IsIdle
- - {
- - get { return _main.IsIdle; }
- - }
- -
- - public void Start()
- - {
- - _bg.Start();
- - }
- -
- - public void Cancel()
- - {
- - _main.Cancel();
- - }
- -
- - public void QueueChange(SourceChange change, ITextSnapshot snapshot)
- - {
- - var edit = new Edit(change, snapshot);
- - _main.QueueChange(edit);
- - }
- -
- - public void Dispose()
- - {
- - _main.Cancel();
- - }
- -
- - public IDisposable SynchronizeMainThreadState()
- - {
- - return _main.Lock();
- - }
- -
- - protected virtual void OnResultsReady(DocumentParseCompleteEventArgs args)
- - {
- - var handler = ResultsReady;
- - if (handler != null)
- - {
- - handler(this, args);
- - }
- - }
- -
- - private static bool TreesAreDifferent(RazorSyntaxTree leftTree, RazorSyntaxTree rightTree, IEnumerable<Edit> edits, CancellationToken cancelToken)
- - {
- - return TreesAreDifferent(leftTree.Root, rightTree.Root, edits.Select(edit => edit.Change), cancelToken);
- - }
- -
- - internal static bool TreesAreDifferent(Block leftTree, Block rightTree, IEnumerable<SourceChange> changes, CancellationToken cancelToken)
- - {
- - // Apply all the pending changes to the original tree
- - // PERF: If this becomes a bottleneck, we can probably do it the other way around,
- - // i.e. visit the tree and find applicable changes for each node.
- - foreach (var change in changes)
- - {
- - cancelToken.ThrowIfCancellationRequested();
- -
- - var changeOwner = leftTree.LocateOwner(change);
- -
- - // Apply the change to the tree
- - if (changeOwner == null)
- - {
- - return true;
- - }
- -
- - var result = changeOwner.EditHandler.ApplyChange(changeOwner, change, force: true);
- - changeOwner.ReplaceWith(result.EditedSpan);
- - }
- -
- - // Now compare the trees
- - var treesDifferent = !leftTree.EquivalentTo(rightTree);
- - return treesDifferent;
- - }
- -
- - private abstract class ThreadStateBase
- - {
- -#if DEBUG
- - private int _id = -1;
- -#endif
- - protected ThreadStateBase()
- - {
- - }
- -
- - [Conditional("DEBUG")]
- - protected void SetThreadId(int id)
- - {
- -#if DEBUG
- - _id = id;
- -#endif
- - }
- -
- - [Conditional("DEBUG")]
- - protected void EnsureOnThread()
- - {
- -#if DEBUG
- - Debug.Assert(_id != -1, "SetThreadId was never called!");
- - Debug.Assert(Thread.CurrentThread.ManagedThreadId == _id, "Called from an unexpected thread!");
- -#endif
- - }
- -
- - [Conditional("DEBUG")]
- - protected void EnsureNotOnThread()
- - {
- -#if DEBUG
- - Debug.Assert(_id != -1, "SetThreadId was never called!");
- - Debug.Assert(Thread.CurrentThread.ManagedThreadId != _id, "Called from an unexpected thread!");
- -#endif
- - }
- - }
- -
- - private class MainThreadState : ThreadStateBase, IDisposable
- - {
- - private readonly CancellationTokenSource _cancelSource = new CancellationTokenSource();
- - private readonly ManualResetEventSlim _hasParcel = new ManualResetEventSlim(false);
- - private CancellationTokenSource _currentParcelCancelSource;
- -
- - private string _fileName;
- - private readonly object _stateLock = new object();
- - private IList<Edit> _changes = new List<Edit>();
- -
- - public MainThreadState(string fileName)
- - {
- - _fileName = fileName;
- -
- - SetThreadId(Thread.CurrentThread.ManagedThreadId);
- - }
- -
- - public event EventHandler<DocumentParseCompleteEventArgs> ResultsReady;
- -
- - public CancellationToken CancelToken
- - {
- - get { return _cancelSource.Token; }
- - }
- -
- - public bool IsIdle
- - {
- - get
- - {
- - lock (_stateLock)
- - {
- - return _currentParcelCancelSource == null;
- - }
- - }
- - }
- -
- - public void Cancel()
- - {
- - EnsureOnThread();
- - _cancelSource.Cancel();
- - }
- -
- - public IDisposable Lock()
- - {
- - Monitor.Enter(_stateLock);
- - return new DisposableAction(() => Monitor.Exit(_stateLock));
- - }
- -
- - public void QueueChange(Edit edit)
- - {
- - EnsureOnThread();
- - lock (_stateLock)
- - {
- - // CurrentParcel token source is not null ==> There's a parse underway
- - if (_currentParcelCancelSource != null)
- - {
- - _currentParcelCancelSource.Cancel();
- - }
- -
- - _changes.Add(edit);
- - _hasParcel.Set();
- - }
- - }
- -
- - public WorkParcel GetParcel()
- - {
- - EnsureNotOnThread(); // Only the background thread can get a parcel
- - _hasParcel.Wait(_cancelSource.Token);
- - _hasParcel.Reset();
- - lock (_stateLock)
- - {
- - // Create a cancellation source for this parcel
- - _currentParcelCancelSource = new CancellationTokenSource();
- -
- - var changes = _changes;
- - _changes = new List<Edit>();
- - return new WorkParcel(changes, _currentParcelCancelSource.Token);
- - }
- - }
- -
- - public void ReturnParcel(DocumentParseCompleteEventArgs args)
- - {
- - lock (_stateLock)
- - {
- - // Clear the current parcel cancellation source
- - if (_currentParcelCancelSource != null)
- - {
- - _currentParcelCancelSource.Dispose();
- - _currentParcelCancelSource = null;
- - }
- -
- - // If there are things waiting to be parsed, just don't fire the event because we're already out of date
- - if (_changes.Any())
- - {
- - return;
- - }
- - }
- - var handler = ResultsReady;
- - if (handler != null)
- - {
- - handler(this, args);
- - }
- - }
- -
- - public void Dispose()
- - {
- - Dispose(true);
- - GC.SuppressFinalize(this);
- - }
- -
- - protected virtual void Dispose(bool disposing)
- - {
- - if (disposing)
- - {
- - if (_currentParcelCancelSource != null)
- - {
- - _currentParcelCancelSource.Dispose();
- - _currentParcelCancelSource = null;
- - }
- - _cancelSource.Dispose();
- - _hasParcel.Dispose();
- - }
- - }
- - }
- -
- - private class BackgroundThread : ThreadStateBase
- - {
- - private MainThreadState _main;
- - private Thread _backgroundThread;
- - private CancellationToken _shutdownToken;
- - private RazorEditorParser _parser;
- - private string _filePath;
- - private RazorSyntaxTree _currentSyntaxTree;
- - private IList<Edit> _previouslyDiscarded = new List<Edit>();
- -
- - public BackgroundThread(MainThreadState main, RazorEditorParser parser, string fileName)
- - {
- - // Run on MAIN thread!
- - _main = main;
- - _shutdownToken = _main.CancelToken;
- - _parser = parser;
- - _filePath = fileName;
- -
- - _backgroundThread = new Thread(WorkerLoop);
- - SetThreadId(_backgroundThread.ManagedThreadId);
- - }
- -
- - // **** ANY THREAD ****
- - public void Start()
- - {
- - _backgroundThread.Start();
- - }
- -
- - // **** BACKGROUND THREAD ****
- - private void WorkerLoop()
- - {
- - var fileNameOnly = Path.GetFileName(_filePath);
- -
- - try
- - {
- - EnsureOnThread();
- -
- - while (!_shutdownToken.IsCancellationRequested)
- - {
- - // Grab the parcel of work to do
- - var parcel = _main.GetParcel();
- - if (parcel.Edits.Any())
- - {
- - try
- - {
- - DocumentParseCompleteEventArgs args = null;
- - using (var linkedCancel = CancellationTokenSource.CreateLinkedTokenSource(_shutdownToken, parcel.CancelToken))
- - {
- - if (!linkedCancel.IsCancellationRequested)
- - {
- - // Collect ALL changes
- - List<Edit> allEdits;
- -
- - if (_previouslyDiscarded != null)
- - {
- - allEdits = Enumerable.Concat(_previouslyDiscarded, parcel.Edits).ToList();
- - }
- - else
- - {
- - allEdits = parcel.Edits.ToList();
- - }
- -
- - var finalEdit = allEdits.Last();
- -
- - var results = ParseChange(finalEdit.Snapshot, linkedCancel.Token);
- -
- - if (results != null && !linkedCancel.IsCancellationRequested)
- - {
- - // Clear discarded changes list
- - _previouslyDiscarded = null;
- -
- - var treeStructureChanged = _currentSyntaxTree == null || TreesAreDifferent(_currentSyntaxTree, results.GetSyntaxTree(), allEdits, parcel.CancelToken);
- - _currentSyntaxTree = results.GetSyntaxTree();
- -
- - // Build Arguments
- - args = new DocumentParseCompleteEventArgs(
- - finalEdit.Change,
- - finalEdit.Snapshot,
- - treeStructureChanged,
- - results);
- - }
- - else
- - {
- - // Parse completed but we were cancelled in the mean time. Add these to the discarded changes set
- - _previouslyDiscarded = allEdits;
- - }
- - }
- - }
- - if (args != null)
- - {
- - _main.ReturnParcel(args);
- - }
- - }
- - catch (OperationCanceledException)
- - {
- - }
- - }
- - else
- - {
- - Thread.Yield();
- - }
- - }
- - }
- - catch (OperationCanceledException)
- - {
- - // Do nothing. Just shut down.
- - }
- - finally
- - {
- - // Clean up main thread resources
- - _main.Dispose();
- - }
- - }
- -
- - private RazorCodeDocument ParseChange(ITextSnapshot snapshot, CancellationToken token)
- - {
- - EnsureOnThread();
- -
- - var templateEngine = _parser.TemplateEngine;
- - var sourceDocument = new TextSnapshotSourceDocument(snapshot, _filePath);
- - var imports = templateEngine.GetImports(_filePath);
- -
- - var codeDocument = RazorCodeDocument.Create(sourceDocument, imports);
- -
- - templateEngine.GenerateCode(codeDocument);
- - return codeDocument;
- - }
- - }
- -
- - private class WorkParcel
- - {
- - public WorkParcel(IList<Edit> changes, CancellationToken cancelToken)
- - {
- - Edits = changes;
- - CancelToken = cancelToken;
- - }
- -
- - public CancellationToken CancelToken { get; }
- -
- - public IList<Edit> Edits { get; }
- - }
- -
- - private class Edit
- - {
- - public Edit(SourceChange change, ITextSnapshot snapshot)
- - {
- - Change = change;
- - Snapshot = snapshot;
- - }
- -
- - public SourceChange Change { get; }
- -
- - public ITextSnapshot Snapshot { get; set; }
- - }
- - }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorSyntaxFactsService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorSyntaxFactsService.cs
- deleted file mode 100644
- index 6b187680e92..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorSyntaxFactsService.cs
- +++ /dev/null
- @@ -1,22 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System.Collections.Generic;
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.VisualStudio.Text;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public abstract class RazorSyntaxFactsService
- - {
- - public abstract IReadOnlyList<ClassifiedSpan> GetClassifiedSpans(RazorSyntaxTree syntaxTree);
- -
- - public abstract IReadOnlyList<TagHelperSpan> GetTagHelperSpans(RazorSyntaxTree syntaxTree);
- -
- - public abstract int? GetDesiredIndentation(RazorSyntaxTree syntaxTree, ITextSnapshot syntaxTreeSnapshot, ITextSnapshotLine line, int indentSize, int tabSize);
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorTemplateEngineFactoryService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorTemplateEngineFactoryService.cs
- deleted file mode 100644
- index 784437df224..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/RazorTemplateEngineFactoryService.cs
- +++ /dev/null
- @@ -1,17 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public abstract class RazorTemplateEngineFactoryService
- - {
- - public abstract RazorTemplateEngine Create(string projectPath, Action<IRazorEngineBuilder> configure);
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/SpanKind.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/SpanKind.cs
- deleted file mode 100644
- index d557849f6d3..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/SpanKind.cs
- +++ /dev/null
- @@ -1,18 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public enum SpanKind
- - {
- - Transition,
- - MetaCode,
- - Comment,
- - Code,
- - Markup
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperCompletionService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperCompletionService.cs
- deleted file mode 100644
- index 78f3e4b8216..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperCompletionService.cs
- +++ /dev/null
- @@ -1,16 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public abstract class TagHelperCompletionService
- - {
- - public abstract AttributeCompletionResult GetAttributeCompletions(AttributeCompletionContext completionContext);
- -
- - public abstract ElementCompletionResult GetElementCompletions(ElementCompletionContext completionContext);
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperFactsService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperFactsService.cs
- deleted file mode 100644
- index 5fca65c2189..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperFactsService.cs
- +++ /dev/null
- @@ -1,23 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System.Collections.Generic;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public abstract class TagHelperFactsService
- - {
- - public abstract TagHelperBinding GetTagHelperBinding(TagHelperDocumentContext documentContext, string tagName, IEnumerable<KeyValuePair<string, string>> attributes, string parentTag);
- -
- - public abstract IEnumerable<BoundAttributeDescriptor> GetBoundTagHelperAttributes(TagHelperDocumentContext documentContext, string attributeName, TagHelperBinding binding);
- -
- - public abstract IReadOnlyList<TagHelperDescriptor> GetTagHelpersGivenTag(TagHelperDocumentContext documentContext, string tagName, string parentTag);
- -
- - public abstract IReadOnlyList<TagHelperDescriptor> GetTagHelpersGivenParent(TagHelperDocumentContext documentContext, string parentTag);
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperSpan.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperSpan.cs
- deleted file mode 100644
- index 337234f3d00..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/TagHelperSpan.cs
- +++ /dev/null
- @@ -1,33 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using Microsoft.AspNetCore.Razor.Language;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - // ----------------------------------------------------------------------------------------------------
- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
- - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
- - // ----------------------------------------------------------------------------------------------------
- - public struct TagHelperSpan
- - {
- - public TagHelperSpan(SourceSpan span, TagHelperBinding binding)
- - {
- - if (binding == null)
- - {
- - throw new ArgumentNullException(nameof(binding));
- - }
- -
- - Span = span;
- - Binding = binding;
- - }
- -
- - public TagHelperBinding Binding { get; }
- -
- - public IEnumerable<TagHelperDescriptor> TagHelpers => Binding.Descriptors;
- -
- - public SourceSpan Span { get; }
- - }
- -}
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorDiagnosticJsonConverter.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorDiagnosticJsonConverter.cs
- index 96db50dc928..d9d4d966e16 100644
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorDiagnosticJsonConverter.cs
- +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorDiagnosticJsonConverter.cs
- @@ -9,7 +9,7 @@ using Newtonsoft.Json.Linq;
-
- namespace Microsoft.VisualStudio.LanguageServices.Razor
- {
- - public class RazorDiagnosticJsonConverter : JsonConverter
- + internal class RazorDiagnosticJsonConverter : JsonConverter
- {
- public static readonly RazorDiagnosticJsonConverter Instance = new RazorDiagnosticJsonConverter();
- private const string RazorDiagnosticMessageKey = "Message";
- diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorLanguageServiceException.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorLanguageServiceException.cs
- deleted file mode 100644
- index 80c5d88a61b..00000000000
- --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorLanguageServiceException.cs
- +++ /dev/null
- @@ -1,15 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - public sealed class RazorLanguageServiceException : Exception
- - {
- - internal RazorLanguageServiceException(string callerClass, string callerMethod, Exception innerException)
- - : base(Resources.FormatUnexpectedException(callerClass, callerMethod), innerException)
- - {
- - }
- - }
- -}
- diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Editor/LegacyTextBufferCodeDocumentProviderTest.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Editor/LegacyTextBufferCodeDocumentProviderTest.cs
- deleted file mode 100644
- index 41278519286..00000000000
- --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Editor/LegacyTextBufferCodeDocumentProviderTest.cs
- +++ /dev/null
- @@ -1,99 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.VisualStudio.Editor.Razor;
- -using Microsoft.VisualStudio.Text;
- -using Microsoft.VisualStudio.Utilities;
- -using Moq;
- -using Xunit;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
- -{
- - public class LegacyTextBufferCodeDocumentProviderTest
- - {
- - [Fact]
- - public void TryGetFromBuffer_UsesVisualStudioRazorParserIfAvailable()
- - {
- - // Arrange
- - var expectedCodeDocument = TestRazorCodeDocument.Create("Hello World");
- - var parser = new DefaultVisualStudioRazorParser(expectedCodeDocument);
- - var properties = new PropertyCollection();
- - properties.AddProperty(typeof(VisualStudioRazorParser), parser);
- - var textBuffer = new Mock<ITextBuffer>();
- - textBuffer.Setup(buffer => buffer.Properties)
- - .Returns(properties);
- - var provider = new LegacyTextBufferCodeDocumentProvider();
- -
- - // Act
- - var result = provider.TryGetFromBuffer(textBuffer.Object, out var codeDocument);
- -
- - // Assert
- - Assert.True(result);
- - Assert.Same(expectedCodeDocument, codeDocument);
- - }
- -
- - [Fact]
- - public void TryGetFromBuffer_UsesRazorEditorParserIfAvailable()
- - {
- - // Arrange
- - var expectedCodeDocument = TestRazorCodeDocument.Create("Hello World");
- - var parser = new RazorEditorParser(expectedCodeDocument);
- - var properties = new PropertyCollection();
- - properties.AddProperty(typeof(RazorEditorParser), parser);
- - var textBuffer = new Mock<ITextBuffer>();
- - textBuffer.Setup(buffer => buffer.Properties)
- - .Returns(properties);
- - var provider = new LegacyTextBufferCodeDocumentProvider();
- -
- - // Act
- - var result = provider.TryGetFromBuffer(textBuffer.Object, out var codeDocument);
- -
- - // Assert
- - Assert.True(result);
- - Assert.Same(expectedCodeDocument, codeDocument);
- - }
- -
- - [Fact]
- - public void TryGetFromBuffer_PrefersVisualStudioRazorParserIfRazorEditorParserIsAvailable()
- - {
- - // Arrange
- - var properties = new PropertyCollection();
- - var expectedCodeDocument = TestRazorCodeDocument.Create("Hello World");
- - var parser = new DefaultVisualStudioRazorParser(expectedCodeDocument);
- - properties.AddProperty(typeof(VisualStudioRazorParser), parser);
- - var unexpectedCodeDocument = TestRazorCodeDocument.Create("Unexpected");
- - var legacyParser = new RazorEditorParser(unexpectedCodeDocument);
- - properties.AddProperty(typeof(RazorEditorParser), legacyParser);
- - var textBuffer = new Mock<ITextBuffer>();
- - textBuffer.Setup(buffer => buffer.Properties)
- - .Returns(properties);
- - var provider = new LegacyTextBufferCodeDocumentProvider();
- -
- - // Act
- - var result = provider.TryGetFromBuffer(textBuffer.Object, out var codeDocument);
- -
- - // Assert
- - Assert.True(result);
- - Assert.Same(expectedCodeDocument, codeDocument);
- - }
- -
- - [Fact]
- - public void TryGetFromBuffer_FailsIfNoParserIsAvailable()
- - {
- - // Arrange
- - var properties = new PropertyCollection();
- - var textBuffer = new Mock<ITextBuffer>();
- - textBuffer.Setup(buffer => buffer.Properties)
- - .Returns(properties);
- - var provider = new LegacyTextBufferCodeDocumentProvider();
- -
- - // Act
- - var result = provider.TryGetFromBuffer(textBuffer.Object, out var codeDocument);
- -
- - // Assert
- - Assert.False(result);
- - Assert.Null(codeDocument);
- - }
- - }
- -}
- diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/DefaultTagHelperCompletionServiceTest.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/DefaultTagHelperCompletionServiceTest.cs
- deleted file mode 100644
- index 5d6ad363bc8..00000000000
- --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/DefaultTagHelperCompletionServiceTest.cs
- +++ /dev/null
- @@ -1,964 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using Microsoft.AspNetCore.Razor.Language;
- -using System.Collections.Generic;
- -using System.Linq;
- -using Xunit;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - public class DefaultTagHelperCompletionServiceTest
- - {
- - [Fact]
- - public void GetAttributeCompletions_DoesNotReturnCompletionsForAlreadySuppliedAttributes()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("div")
- - .RequireAttributeDescriptor(attribute => attribute.Name("repeat")))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("visible")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Visible"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("StyleTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("class")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("Class"))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["onclick"] = new HashSet<BoundAttributeDescriptor>(),
- - ["visible"] = new HashSet<BoundAttributeDescriptor>()
- - {
- - documentDescriptors[0].BoundAttributes.Last()
- - }
- - });
- -
- - var existingCompletions = new[] { "onclick" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - attributes: new Dictionary<string, string>()
- - {
- - ["class"] = "something",
- - ["repeat"] = "4"
- - },
- - currentTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_PossibleDescriptorsReturnUnboundRequiredAttributesWithExistingCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("div")
- - .RequireAttributeDescriptor(attribute => attribute.Name("repeat")))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("StyleTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("*")
- - .RequireAttributeDescriptor(attribute => attribute.Name("class")))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["class"] = new HashSet<BoundAttributeDescriptor>(),
- - ["onclick"] = new HashSet<BoundAttributeDescriptor>(),
- - ["repeat"] = new HashSet<BoundAttributeDescriptor>()
- - });
- -
- - var existingCompletions = new[] { "onclick", "class" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_PossibleDescriptorsReturnBoundRequiredAttributesWithExistingCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("div")
- - .RequireAttributeDescriptor(attribute => attribute.Name("repeat")))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("repeat")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Repeat"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("visible")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Visible"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("StyleTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("*")
- - .RequireAttributeDescriptor(attribute => attribute.Name("class")))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("class")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("Class"))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["class"] = new HashSet<BoundAttributeDescriptor>(documentDescriptors[1].BoundAttributes),
- - ["onclick"] = new HashSet<BoundAttributeDescriptor>(),
- - ["repeat"] = new HashSet<BoundAttributeDescriptor>()
- - {
- - documentDescriptors[0].BoundAttributes.First()
- - }
- - });
- -
- - var existingCompletions = new[] { "onclick" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_AppliedDescriptorsReturnAllBoundAttributesWithExistingCompletionsForSchemaTags()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("repeat")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Repeat"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("visible")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Visible"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("StyleTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("*")
- - .RequireAttributeDescriptor(attribute => attribute.Name("class")))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("class")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("Class"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("StyleTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("visible")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Visible"))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["onclick"] = new HashSet<BoundAttributeDescriptor>(),
- - ["class"] = new HashSet<BoundAttributeDescriptor>(documentDescriptors[1].BoundAttributes),
- - ["repeat"] = new HashSet<BoundAttributeDescriptor>()
- - {
- - documentDescriptors[0].BoundAttributes.First()
- - },
- - ["visible"] = new HashSet<BoundAttributeDescriptor>()
- - {
- - documentDescriptors[0].BoundAttributes.Last(),
- - documentDescriptors[2].BoundAttributes.First(),
- - }
- - });
- -
- - var existingCompletions = new[] { "class", "onclick" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_AppliedTagOutputHintDescriptorsReturnBoundAttributesWithExistingCompletionsForNonSchemaTags()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("CustomTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("custom"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("repeat")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Repeat"))
- - .TagOutputHint("div")
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["class"] = new HashSet<BoundAttributeDescriptor>(),
- - ["repeat"] = new HashSet<BoundAttributeDescriptor>(documentDescriptors[0].BoundAttributes)
- - });
- -
- - var existingCompletions = new[] { "class" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "custom");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_AppliedDescriptorsReturnBoundAttributesCompletionsForNonSchemaTags()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("CustomTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("custom"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("repeat")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Repeat"))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["repeat"] = new HashSet<BoundAttributeDescriptor>(documentDescriptors[0].BoundAttributes)
- - });
- -
- - var existingCompletions = new[] { "class" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "custom");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_AppliedDescriptorsReturnBoundAttributesWithExistingCompletionsForSchemaTags()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .BoundAttributeDescriptor(attribute => attribute
- - .Name("repeat")
- - .TypeName(typeof(bool).FullName)
- - .PropertyName("Repeat"))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["class"] = new HashSet<BoundAttributeDescriptor>(),
- - ["repeat"] = new HashSet<BoundAttributeDescriptor>(documentDescriptors[0].BoundAttributes)
- - });
- -
- - var existingCompletions = new[] { "class" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_NoDescriptorsReturnsExistingCompletions()
- - {
- - // Arrange
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["class"] = new HashSet<BoundAttributeDescriptor>(),
- - });
- -
- - var existingCompletions = new[] { "class" };
- - var completionContext = BuildAttributeCompletionContext(
- - Enumerable.Empty<TagHelperDescriptor>(),
- - existingCompletions,
- - currentTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_NoDescriptorsForUnprefixedTagReturnsExistingCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("div")
- - .RequireAttributeDescriptor(attribute => attribute.Name("special")))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["class"] = new HashSet<BoundAttributeDescriptor>(),
- - });
- -
- - var existingCompletions = new[] { "class" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "div",
- - tagHelperPrefix: "th:");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetAttributeCompletions_NoDescriptorsForTagReturnsExistingCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("MyTableTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("table")
- - .RequireAttributeDescriptor(attribute => attribute.Name("special")))
- - .Build(),
- - };
- - var expectedCompletions = AttributeCompletionResult.Create(new Dictionary<string, HashSet<BoundAttributeDescriptor>>()
- - {
- - ["class"] = new HashSet<BoundAttributeDescriptor>(),
- - });
- -
- - var existingCompletions = new[] { "class" };
- - var completionContext = BuildAttributeCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - currentTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetAttributeCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_TagOutputHintDoesNotFallThroughToSchemaCheck()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("MyTableTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("my-table"))
- - .TagOutputHint("table")
- - .Build(),
- - TagHelperDescriptorBuilder.Create("MyTrTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("my-tr"))
- - .TagOutputHint("tr")
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["my-table"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - ["table"] = new HashSet<TagHelperDescriptor>(),
- - });
- -
- - var existingCompletions = new[] { "table" };
- - var completionContext = BuildElementCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - containingTagName: "body",
- - containingParentTagName: null);
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_CatchAllsOnlyApplyToCompletionsStartingWithPrefix()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("CatchAllTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("LiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["th:li"] = new HashSet<TagHelperDescriptor> { documentDescriptors[1], documentDescriptors[0] },
- - ["li"] = new HashSet<TagHelperDescriptor>(),
- - });
- -
- - var existingCompletions = new[] { "li" };
- - var completionContext = BuildElementCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - containingTagName: "ul",
- - tagHelperPrefix: "th:");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_TagHelperPrefixIsPrependedToTagHelperCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("SuperLiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("superli"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("LiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["th:superli"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - ["th:li"] = new HashSet<TagHelperDescriptor> { documentDescriptors[1] },
- - ["li"] = new HashSet<TagHelperDescriptor>(),
- - });
- -
- - var existingCompletions = new[] { "li" };
- - var completionContext = BuildElementCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - containingTagName: "ul",
- - tagHelperPrefix: "th:");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_CatchAllsApplyToOnlyTagHelperCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("SuperLiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("superli"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("CatchAll", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["superli"] = new HashSet<TagHelperDescriptor>() { documentDescriptors[0], documentDescriptors[1] },
- - ["li"] = new HashSet<TagHelperDescriptor>(),
- - });
- -
- - var existingCompletions = new[] { "li" };
- - var completionContext = BuildElementCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - containingTagName: "ul");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_CatchAllsApplyToNonTagHelperCompletionsIfStartsWithTagHelperPrefix()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("SuperLiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("superli"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("CatchAll", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["th:superli"] = new HashSet<TagHelperDescriptor>() { documentDescriptors[0], documentDescriptors[1] },
- - ["th:li"] = new HashSet<TagHelperDescriptor>() { documentDescriptors[1] },
- - });
- -
- - var existingCompletions = new[] { "th:li" };
- - var completionContext = BuildElementCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - containingTagName: "ul",
- - tagHelperPrefix: "th:");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_AllowsMultiTargetingTagHelpers()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("BoldTagHelper1", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("strong"))
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("b"))
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("bold"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("BoldTagHelper2", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("strong"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["strong"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0], documentDescriptors[1] },
- - ["b"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - ["bold"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - });
- -
- - var existingCompletions = new[] { "strong", "b", "bold" };
- - var completionContext = BuildElementCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - containingTagName: "ul");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_CombinesDescriptorsOnExistingCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("LiTagHelper1", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("LiTagHelper2", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["li"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0], documentDescriptors[1] },
- - });
- -
- - var existingCompletions = new[] { "li" };
- - var completionContext = BuildElementCompletionContext(documentDescriptors, existingCompletions, containingTagName: "ul");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_NewCompletionsForSchemaTagsNotInExistingCompletionsAreIgnored()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("SuperLiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("superli"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("LiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li"))
- - .TagOutputHint("strong")
- - .Build(),
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["li"] = new HashSet<TagHelperDescriptor> { documentDescriptors[1] },
- - ["superli"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - });
- -
- - var existingCompletions = new[] { "li" };
- - var completionContext = BuildElementCompletionContext(documentDescriptors, existingCompletions, containingTagName: "ul");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_OutputHintIsCrossReferencedWithExistingCompletions()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .TagOutputHint("li")
- - .Build(),
- - TagHelperDescriptorBuilder.Create("LiTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li"))
- - .TagOutputHint("strong")
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["div"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - ["li"] = new HashSet<TagHelperDescriptor> { documentDescriptors[1] },
- - });
- -
- - var existingCompletions = new[] { "li" };
- - var completionContext = BuildElementCompletionContext(documentDescriptors, existingCompletions, containingTagName: "ul");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_EnsuresDescriptorsHaveSatisfiedParent()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("LiTagHelper1", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("LiTagHelper2", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("li").RequireParentTag("ol"))
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["li"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - });
- -
- - var existingCompletions = new[] { "li" };
- - var completionContext = BuildElementCompletionContext(documentDescriptors, existingCompletions, containingTagName: "ul");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_AllowedChildrenAreIgnoredWhenAtRoot()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("CatchAll", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .AllowChildTag("b")
- - .AllowChildTag("bold")
- - .AllowChildTag("div")
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>());
- -
- - var existingCompletions = Enumerable.Empty<string>();
- - var completionContext = BuildElementCompletionContext(
- - documentDescriptors,
- - existingCompletions,
- - containingTagName: null,
- - containingParentTagName: null);
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_DoesNotReturnExistingCompletionsWhenAllowedChildren()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("BoldParent", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .AllowChildTag("b")
- - .AllowChildTag("bold")
- - .AllowChildTag("div")
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["b"] = new HashSet<TagHelperDescriptor>(),
- - ["bold"] = new HashSet<TagHelperDescriptor>(),
- - ["div"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] }
- - });
- -
- - var existingCompletions = new[] { "p", "em" };
- - var completionContext = BuildElementCompletionContext(documentDescriptors, existingCompletions, containingTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_CapturesAllAllowedChildTagsFromParentTagHelpers_NoneTagHelpers()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("BoldParent", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .AllowChildTag("b")
- - .AllowChildTag("bold")
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["b"] = new HashSet<TagHelperDescriptor>(),
- - ["bold"] = new HashSet<TagHelperDescriptor>(),
- - });
- -
- - var completionContext = BuildElementCompletionContext(documentDescriptors, Enumerable.Empty<string>(), containingTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_CapturesAllAllowedChildTagsFromParentTagHelpers_SomeTagHelpers()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("BoldParent", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .AllowChildTag("b")
- - .AllowChildTag("bold")
- - .AllowChildTag("div")
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["b"] = new HashSet<TagHelperDescriptor>(),
- - ["bold"] = new HashSet<TagHelperDescriptor>(),
- - ["div"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] }
- - });
- -
- - var completionContext = BuildElementCompletionContext(documentDescriptors, Enumerable.Empty<string>(), containingTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - [Fact]
- - public void GetElementCompletions_CapturesAllAllowedChildTagsFromParentTagHelpers_AllTagHelpers()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("BoldParentCatchAll", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .AllowChildTag("strong")
- - .AllowChildTag("div")
- - .AllowChildTag("b")
- - .Build(),
- - TagHelperDescriptorBuilder.Create("BoldParent", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .AllowChildTag("b")
- - .AllowChildTag("bold")
- - .Build(),
- - };
- - var expectedCompletions = ElementCompletionResult.Create(new Dictionary<string, HashSet<TagHelperDescriptor>>()
- - {
- - ["strong"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - ["b"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - ["bold"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0] },
- - ["div"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0], documentDescriptors[1] },
- - });
- -
- - var completionContext = BuildElementCompletionContext(documentDescriptors, Enumerable.Empty<string>(), containingTagName: "div");
- - var service = CreateTagHelperCompletionFactsService();
- -
- - // Act
- - var completions = service.GetElementCompletions(completionContext);
- -
- - // Assert
- - AssertCompletionsAreEquivalent(expectedCompletions, completions);
- - }
- -
- - private static DefaultTagHelperCompletionService CreateTagHelperCompletionFactsService()
- - {
- - var tagHelperFactService = new DefaultTagHelperFactsService();
- - var completionFactService = new DefaultTagHelperCompletionService(tagHelperFactService);
- -
- - return completionFactService;
- - }
- -
- - private static void AssertCompletionsAreEquivalent(ElementCompletionResult expected, ElementCompletionResult actual)
- - {
- - Assert.Equal(expected.Completions.Count, actual.Completions.Count);
- -
- - foreach (var expectedCompletion in expected.Completions)
- - {
- - var actualValue = actual.Completions[expectedCompletion.Key];
- - Assert.NotNull(actualValue);
- - Assert.Equal(expectedCompletion.Value, actualValue, TagHelperDescriptorComparer.CaseSensitive);
- - }
- - }
- -
- - private static void AssertCompletionsAreEquivalent(AttributeCompletionResult expected, AttributeCompletionResult actual)
- - {
- - Assert.Equal(expected.Completions.Count, actual.Completions.Count);
- -
- - foreach (var expectedCompletion in expected.Completions)
- - {
- - var actualValue = actual.Completions[expectedCompletion.Key];
- - Assert.NotNull(actualValue);
- - Assert.Equal(expectedCompletion.Value, actualValue, BoundAttributeDescriptorComparer.CaseSensitive);
- - }
- - }
- -
- - private static ElementCompletionContext BuildElementCompletionContext(
- - IEnumerable<TagHelperDescriptor> descriptors,
- - IEnumerable<string> existingCompletions,
- - string containingTagName,
- - string containingParentTagName = "body",
- - string tagHelperPrefix = "")
- - {
- - var documentContext = TagHelperDocumentContext.Create(tagHelperPrefix, descriptors);
- - var completionContext = new ElementCompletionContext(
- - documentContext,
- - existingCompletions,
- - containingTagName,
- - attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
- - containingParentTagName: containingParentTagName,
- - inHTMLSchema: (tag) => tag == "strong" || tag == "b" || tag == "bold" || tag == "li" || tag == "div");
- -
- - return completionContext;
- - }
- -
- - private static AttributeCompletionContext BuildAttributeCompletionContext(
- - IEnumerable<TagHelperDescriptor> descriptors,
- - IEnumerable<string> existingCompletions,
- - string currentTagName,
- - IEnumerable<KeyValuePair<string, string>> attributes = null,
- - string tagHelperPrefix = "")
- - {
- - attributes = attributes ?? Enumerable.Empty<KeyValuePair<string, string>>();
- - var documentContext = TagHelperDocumentContext.Create(tagHelperPrefix, descriptors);
- - var completionContext = new AttributeCompletionContext(
- - documentContext,
- - existingCompletions,
- - currentTagName,
- - attributes,
- - currentParentTagName: "body",
- - inHTMLSchema: (tag) => tag == "strong" || tag == "b" || tag == "bold" || tag == "li" || tag == "div");
- -
- - return completionContext;
- - }
- - }
- -}
- \ No newline at end of file
- diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/DefaultTagHelperFactsServiceTest.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/DefaultTagHelperFactsServiceTest.cs
- deleted file mode 100644
- index f62597b32f2..00000000000
- --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/DefaultTagHelperFactsServiceTest.cs
- +++ /dev/null
- @@ -1,388 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using Microsoft.AspNetCore.Razor.Language;
- -using System.Collections.Generic;
- -using System.Linq;
- -using Xunit;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - public class DefaultTagHelperFactsServiceTest
- - {
- - // Purposefully not thoroughly testing DefaultTagHelperFactsService.GetTagHelperBinding because it's a pass through
- - // into TagHelperDescriptorProvider.GetTagHelperBinding.
- -
- - [Fact]
- - public void GetTagHelperBinding_DoesNotAllowOptOutCharacterPrefix()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var binding = service.GetTagHelperBinding(documentContext, "!a", Enumerable.Empty<KeyValuePair<string, string>>(), parentTag: null);
- -
- - // Assert
- - Assert.Null(binding);
- - }
- -
- - [Fact]
- - public void GetTagHelperBinding_WorksAsExpected()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule =>
- - rule
- - .RequireTagName("a")
- - .RequireAttributeDescriptor(attribute => attribute.Name("asp-for")))
- - .BoundAttributeDescriptor(attribute =>
- - attribute
- - .Name("asp-for")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("AspFor"))
- - .BoundAttributeDescriptor(attribute =>
- - attribute
- - .Name("asp-route")
- - .TypeName(typeof(IDictionary<string, string>).Namespace + "IDictionary<string, string>")
- - .PropertyName("AspRoute")
- - .AsDictionaryAttribute("asp-route-", typeof(string).FullName))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("input"))
- - .BoundAttributeDescriptor(attribute =>
- - attribute
- - .Name("asp-for")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("AspFor"))
- - .Build(),
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- - var attributes = new[]
- - {
- - new KeyValuePair<string, string>("asp-for", "Name")
- - };
- -
- - // Act
- - var binding = service.GetTagHelperBinding(documentContext, "a", attributes, parentTag: "p");
- -
- - // Assert
- - var descriptor = Assert.Single(binding.Descriptors);
- - Assert.Equal(documentDescriptors[0], descriptor, TagHelperDescriptorComparer.CaseSensitive);
- - var boundRule = Assert.Single(binding.GetBoundRules(descriptor));
- - Assert.Equal(documentDescriptors[0].TagMatchingRules.First(), boundRule, TagMatchingRuleDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetBoundTagHelperAttributes_MatchesPrefixedAttributeName()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("a"))
- - .BoundAttributeDescriptor(attribute =>
- - attribute
- - .Name("asp-for")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("AspFor"))
- - .BoundAttributeDescriptor(attribute =>
- - attribute
- - .Name("asp-route")
- - .TypeName(typeof(IDictionary<string, string>).Namespace + "IDictionary<string, string>")
- - .PropertyName("AspRoute")
- - .AsDictionaryAttribute("asp-route-", typeof(string).FullName))
- - .Build()
- - };
- - var expectedAttributeDescriptors = new[]
- - {
- - documentDescriptors[0].BoundAttributes.Last()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- - var binding = service.GetTagHelperBinding(documentContext, "a", Enumerable.Empty<KeyValuePair<string, string>>(), parentTag: null);
- -
- - // Act
- - var descriptors = service.GetBoundTagHelperAttributes(documentContext, "asp-route-something", binding);
- -
- - // Assert
- - Assert.Equal(expectedAttributeDescriptors, descriptors, BoundAttributeDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetBoundTagHelperAttributes_MatchesAttributeName()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("input"))
- - .BoundAttributeDescriptor(attribute =>
- - attribute
- - .Name("asp-for")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("AspFor"))
- - .BoundAttributeDescriptor(attribute =>
- - attribute
- - .Name("asp-extra")
- - .TypeName(typeof(string).FullName)
- - .PropertyName("AspExtra"))
- - .Build()
- - };
- - var expectedAttributeDescriptors = new[]
- - {
- - documentDescriptors[0].BoundAttributes.First()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- - var binding = service.GetTagHelperBinding(documentContext, "input", Enumerable.Empty<KeyValuePair<string, string>>(), parentTag: null);
- -
- - // Act
- - var descriptors = service.GetBoundTagHelperAttributes(documentContext, "asp-for", binding);
- -
- - // Assert
- - Assert.Equal(expectedAttributeDescriptors, descriptors, BoundAttributeDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenTag_DoesNotAllowOptOutCharacterPrefix()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenTag(documentContext, "!strong", parentTag: null);
- -
- - // Assert
- - Assert.Empty(descriptors);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenTag_RequiresTagName()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("strong"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenTag(documentContext, "strong", "p");
- -
- - // Assert
- - Assert.Equal(documentDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenTag_RestrictsTagHelpersBasedOnTagName()
- - {
- - // Arrange
- - var expectedDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(
- - rule => rule
- - .RequireTagName("a")
- - .RequireParentTag("div"))
- - .Build()
- - };
- - var documentDescriptors = new[]
- - {
- - expectedDescriptors[0],
- - TagHelperDescriptorBuilder.Create("TestType2", "TestAssembly")
- - .TagMatchingRuleDescriptor(
- - rule => rule
- - .RequireTagName("strong")
- - .RequireParentTag("div"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenTag(documentContext, "a", "div");
- -
- - // Assert
- - Assert.Equal(expectedDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenTag_RestrictsTagHelpersBasedOnTagHelperPrefix()
- - {
- - // Arrange
- - var expectedDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("strong"))
- - .Build()
- - };
- - var documentDescriptors = new[]
- - {
- - expectedDescriptors[0],
- - TagHelperDescriptorBuilder.Create("TestType2", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("thstrong"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create("th", documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenTag(documentContext, "thstrong", "div");
- -
- - // Assert
- - Assert.Equal(expectedDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenTag_RestrictsTagHelpersBasedOnParent()
- - {
- - // Arrange
- - var expectedDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(
- - rule => rule
- - .RequireTagName("strong")
- - .RequireParentTag("div"))
- - .Build()
- - };
- - var documentDescriptors = new[]
- - {
- - expectedDescriptors[0],
- - TagHelperDescriptorBuilder.Create("TestType2", "TestAssembly")
- - .TagMatchingRuleDescriptor(
- - rule => rule
- - .RequireTagName("strong")
- - .RequireParentTag("p"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenTag(documentContext, "strong", "div");
- -
- - // Assert
- - Assert.Equal(expectedDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenParent_AllowsRootParentTag()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenParent(documentContext, parentTag: null /* root */);
- -
- - // Assert
- - Assert.Equal(documentDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenParent_AllowsRootParentTagForParentRestrictedTagHelperDescriptors()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .Build(),
- - TagHelperDescriptorBuilder.Create("PTagHelper", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule
- - .RequireTagName("p")
- - .RequireParentTag("body"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenParent(documentContext, parentTag: null /* root */);
- -
- - // Assert
- - var descriptor = Assert.Single(descriptors);
- - Assert.Equal(documentDescriptors[0], descriptor, TagHelperDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenParent_AllowsUnspecifiedParentTagHelpers()
- - {
- - // Arrange
- - var documentDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenParent(documentContext, "p");
- -
- - // Assert
- - Assert.Equal(documentDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
- - }
- -
- - [Fact]
- - public void GetTagHelpersGivenParent_RestrictsTagHelpersBasedOnParent()
- - {
- - // Arrange
- - var expectedDescriptors = new[]
- - {
- - TagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
- - .TagMatchingRuleDescriptor(
- - rule => rule
- - .RequireTagName("p")
- - .RequireParentTag("div"))
- - .Build()
- - };
- - var documentDescriptors = new[]
- - {
- - expectedDescriptors[0],
- - TagHelperDescriptorBuilder.Create("TestType2", "TestAssembly")
- - .TagMatchingRuleDescriptor(
- - rule => rule
- - .RequireTagName("strong")
- - .RequireParentTag("p"))
- - .Build()
- - };
- - var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
- - var service = new DefaultTagHelperFactsService();
- -
- - // Act
- - var descriptors = service.GetTagHelpersGivenParent(documentContext, "div");
- -
- - // Assert
- - Assert.Equal(expectedDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
- - }
- - }
- -}
- \ No newline at end of file
- diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/RazorEditorParserTest.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/RazorEditorParserTest.cs
- deleted file mode 100644
- index 0f6e3e32e91..00000000000
- --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Legacy/RazorEditorParserTest.cs
- +++ /dev/null
- @@ -1,1345 +0,0 @@
- -// Copyright (c) .NET Foundation. All rights reserved.
- -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
- -
- -using System;
- -using System.Collections.Generic;
- -using System.Diagnostics;
- -using System.Threading;
- -using Microsoft.AspNetCore.Mvc.Razor.Extensions;
- -using Microsoft.AspNetCore.Razor.Language;
- -using Microsoft.AspNetCore.Razor.Language.Legacy;
- -using Microsoft.VisualStudio.Text;
- -using Xunit;
- -
- -namespace Microsoft.VisualStudio.LanguageServices.Razor
- -{
- - public class RazorEditorParserTest
- - {
- - private static readonly TestFile SimpleCSHTMLDocument = TestFile.Create("TestFiles/DesignTime/Simple.cshtml", typeof(RazorEditorParserTest));
- - private static readonly TestFile SimpleCSHTMLDocumentGenerated = TestFile.Create("TestFiles/DesignTime/Simple.txt", typeof(RazorEditorParserTest));
- - private const string TestLinePragmaFileName = "C:\\This\\Path\\Is\\Just\\For\\Line\\Pragmas.cshtml";
- -
- - public static TheoryData TagHelperPartialParseRejectData
- - {
- - get
- - {
- - return new TheoryData<TestEdit>
- - {
- - CreateInsertionChange("<p></p>", 2, " "),
- - CreateInsertionChange("<p></p>", 6, " "),
- - CreateInsertionChange("<p some-attr></p>", 12, " "),
- - CreateInsertionChange("<p some-attr></p>", 12, "ibute"),
- - CreateInsertionChange("<p some-attr></p>", 2, " before"),
- - };
- - }
- - }
- -
- - [Theory]
- - [MemberData(nameof(TagHelperPartialParseRejectData))]
- - public void TagHelperTagBodiesRejectPartialChanges(object editObject)
- - {
- - // Arrange
- - var edit = (TestEdit)editObject;
- - var builder = TagHelperDescriptorBuilder.Create("PTagHelper", "TestAssembly");
- - builder.SetTypeName("PTagHelper");
- - builder.TagMatchingRule(rule => rule.TagName = "p");
- - var descriptors = new[]
- - {
- - builder.Build()
- - };
- -
- - var parser = new RazorEditorParser(CreateTemplateEngine(@"C:\This\Is\A\Test\Path"), @"C:\This\Is\A\Test\Path");
- -
- - using (var manager = new TestParserManager(parser))
- - {
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // Act
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Rejected, result);
- - Assert.Equal(2, manager.ParseCount);
- - }
- - }
- -
- - public static TheoryData TagHelperAttributeAcceptData
- - {
- - get
- - {
- - var factory = new SpanFactory();
- -
- - // change, (Block)expectedDocument, partialParseResult
- - return new TheoryData<TestEdit, PartialParseResult>
- - {
- - {
- - CreateInsertionChange("<p str-attr='@DateTime'></p>", 22, "."),
- - PartialParseResult.Accepted | PartialParseResult.Provisional
- - },
- - {
- - CreateInsertionChange("<p obj-attr='DateTime'></p>", 21, "."),
- - PartialParseResult.Accepted
- - },
- - {
- - CreateInsertionChange("<p obj-attr='1 + DateTime'></p>", 25, "."),
- - PartialParseResult.Accepted
- - },
- - {
- - CreateInsertionChange("<p before-attr str-attr='@DateTime' after-attr></p>", 34, "."),
- - PartialParseResult.Accepted | PartialParseResult.Provisional
- - },
- - {
- - CreateInsertionChange("<p str-attr='before @DateTime after'></p>", 29, "."),
- - PartialParseResult.Accepted | PartialParseResult.Provisional
- - },
- - };
- - }
- - }
- -
- - [Theory]
- - [MemberData(nameof(TagHelperAttributeAcceptData))]
- - public void TagHelperAttributesAreLocatedAndAcceptChangesCorrectly(object editObject, PartialParseResult partialParseResult)
- - {
- - // Arrange
- - var edit = (TestEdit)editObject;
- - var builder = TagHelperDescriptorBuilder.Create("PTagHelper", "Test");
- - builder.SetTypeName("PTagHelper");
- - builder.TagMatchingRule(rule => rule.TagName = "p");
- - builder.BindAttribute(attribute =>
- - {
- - attribute.Name = "obj-attr";
- - attribute.TypeName = typeof(object).FullName;
- - attribute.SetPropertyName("ObjectAttribute");
- - });
- - builder.BindAttribute(attribute =>
- - {
- - attribute.Name = "str-attr";
- - attribute.TypeName = typeof(string).FullName;
- - attribute.SetPropertyName("StringAttribute");
- - });
- - var descriptors = new[] { builder.Build() };
- -
- - var parser = new RazorEditorParser(CreateTemplateEngine(@"C:\This\Is\A\Test\Path", descriptors), @"C:\This\Is\A\Test\Path");
- -
- - using (var manager = new TestParserManager(parser))
- - {
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // Act
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(partialParseResult, result);
- - Assert.Equal(1, manager.ParseCount);
- - }
- - }
- -
- - [Fact]
- - public void ConstructorRequiresNonNullPhysicalPath()
- - {
- - Assert.Throws<ArgumentException>("filePath", () => new RazorEditorParser(CreateTemplateEngine(), null));
- - }
- -
- - [Fact]
- - public void ConstructorRequiresNonEmptyPhysicalPath()
- - {
- - Assert.Throws<ArgumentException>("filePath", () => new RazorEditorParser(CreateTemplateEngine(), string.Empty));
- - }
- -
- - [Theory]
- - [InlineData(" ")]
- - [InlineData("\r\n")]
- - [InlineData("abcdefg")]
- - [InlineData("\f\r\n abcd \t")]
- - public void TreesAreDifferentReturnsFalseForAddedContent(string content)
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var blockFactory = new BlockFactory(factory);
- - var original = new MarkupBlock(
- - blockFactory.MarkupTagBlock("<p>"),
- - blockFactory.TagHelperBlock(
- - tagName: "div",
- - tagMode: TagMode.StartTagAndEndTag,
- - start: new SourceLocation(3, 0, 3),
- - startTag: blockFactory.MarkupTagBlock("<div>"),
- - children: new SyntaxTreeNode[]
- - {
- - factory.Markup($"{Environment.NewLine}{Environment.NewLine}")
- - },
- - endTag: blockFactory.MarkupTagBlock("</div>")),
- - blockFactory.MarkupTagBlock("</p>"));
- -
- - factory.Reset();
- -
- - var modified = new MarkupBlock(
- - blockFactory.MarkupTagBlock("<p>"),
- - blockFactory.TagHelperBlock(
- - tagName: "div",
- - tagMode: TagMode.StartTagAndEndTag,
- - start: new SourceLocation(3, 0, 3),
- - startTag: blockFactory.MarkupTagBlock("<div>"),
- - children: new SyntaxTreeNode[]
- - {
- - factory.Markup($"{Environment.NewLine}{content}{Environment.NewLine}")
- - },
- - endTag: blockFactory.MarkupTagBlock("</div>")),
- - blockFactory.MarkupTagBlock("</p>"));
- - original.LinkNodes();
- - modified.LinkNodes();
- -
- - // Act
- - var treesAreDifferent = RazorEditorParser.BackgroundParser.TreesAreDifferent(
- - original,
- - modified,
- - new[]
- - {
- - new SourceChange(
- - absoluteIndex: 8 + Environment.NewLine.Length,
- - length: 0,
- - newText: content)
- - },
- - CancellationToken.None);
- -
- - // Assert
- - Assert.False(treesAreDifferent);
- - }
- -
- - [Fact]
- - public void TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent()
- - {
- - var factory = new SpanFactory();
- - var original = new MarkupBlock(
- - factory.Markup("<p>"),
- - new ExpressionBlock(
- - factory.CodeTransition()),
- - factory.Markup("</p>"));
- - var modified = new MarkupBlock(
- - factory.Markup("<p>"),
- - new ExpressionBlock(
- - factory.CodeTransition("@"),
- - factory.Code("f")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
- - factory.Markup("</p>"));
- - Assert.True(RazorEditorParser.BackgroundParser.TreesAreDifferent(
- - original,
- - modified,
- - new[]
- - {
- - new SourceChange(absoluteIndex: 4, length: 0, newText: "f")
- - },
- - CancellationToken.None));
- - }
- -
- - [Fact]
- - public void TreesAreDifferentReturnsFalseIfTreeStructureIsSame()
- - {
- - var factory = new SpanFactory();
- - var original = new MarkupBlock(
- - factory.Markup("<p>"),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("f")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
- - factory.Markup("</p>"));
- - factory.Reset();
- - var modified = new MarkupBlock(
- - factory.Markup("<p>"),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foo")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
- - factory.Markup("</p>"));
- - original.LinkNodes();
- - modified.LinkNodes();
- - Assert.False(RazorEditorParser.BackgroundParser.TreesAreDifferent(
- - original,
- - modified,
- - new[]
- - {
- - new SourceChange(absoluteIndex: 5, length: 0, newText: "oo")
- - },
- - CancellationToken.None));
- - }
- -
- - [Fact]
- - public void CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans()
- - {
- - // Arrange
- - using (var parser = new RazorEditorParser(CreateTemplateEngine(), TestLinePragmaFileName))
- - {
- - var original = new StringTextSnapshot("Foo @bar Baz");
- - var changed = new StringTextSnapshot("Foo @bap Daz");
- - var change = new SourceChange(7, 3, "p D");
- -
- - var parseComplete = new ManualResetEventSlim();
- - var parseCount = 0;
- - parser.DocumentParseComplete += (sender, args) =>
- - {
- - Interlocked.Increment(ref parseCount);
- - parseComplete.Set();
- - };
- -
- - Assert.Equal(PartialParseResult.Rejected, parser.CheckForStructureChanges(change, original));
- - DoWithTimeoutIfNotDebugging(parseComplete.Wait); // Wait for the parse to finish
- - parseComplete.Reset();
- -
- - // Act
- - var result = parser.CheckForStructureChanges(change, original);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Rejected, result);
- - DoWithTimeoutIfNotDebugging(parseComplete.Wait);
- - Assert.Equal(2, parseCount);
- - }
- - }
- -
- - [Fact]
- - public void AwaitPeriodInsertionAcceptedProvisionally()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @await Html. baz");
- - var old = new StringTextSnapshot("foo @await Html baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(15, 0, old, 1, changed, "."),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("await Html.").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.WhiteSpace | AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")), additionalFlags: PartialParseResult.Provisional);
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsInnerInsertionsInStatementBlock()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateTime..Now" + Environment.NewLine
- - + "}");
- - var old = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateTime.Now" + Environment.NewLine
- - + "}");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(17, 0, old, 1, changed, "."),
- - new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.Code(Environment.NewLine + " ")
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime..Now")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Code(Environment.NewLine).AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsInnerInsertions()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @DateTime..Now baz");
- - var old = new StringTextSnapshot("foo @DateTime.Now baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(13, 0, old, 1, changed, "."),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime..Now").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")), additionalFlags: PartialParseResult.Provisional);
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsWholeIdentifierReplacement()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var old = new StringTextSnapshot("foo @date baz");
- - var changed = new StringTextSnapshot("foo @DateTime baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(5, 4, old, 8, changed, "DateTime"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionRejectsWholeIdentifierReplacementToKeyword()
- - {
- - // Arrange
- - var parser = new RazorEditorParser(CreateTemplateEngine(@"C:\This\Is\A\Test\Path"), @"C:\This\Is\A\Test\Path");
- -
- - using (var manager = new TestParserManager(parser))
- - {
- - var old = new StringTextSnapshot("foo @date baz");
- - var changed = new StringTextSnapshot("foo @if baz");
- - var edit = new TestEdit(5, 4, old, 2, changed, "if");
- - manager.InitializeWithDocument(old);
- -
- - // Act
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Rejected, result);
- - Assert.Equal(2, manager.ParseCount);
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionRejectsWholeIdentifierReplacementToDirective()
- - {
- - // Arrange
- - var parser = new RazorEditorParser(CreateTemplateEngine(@"C:\This\Is\A\Test\Path"), @"C:\This\Is\A\Test\Path");
- -
- - using (var manager = new TestParserManager(parser))
- - {
- - var old = new StringTextSnapshot("foo @date baz");
- - var changed = new StringTextSnapshot("foo @inherits baz");
- - var SourceChange = new TestEdit(5, 4, old, 8, changed, "inherits");
- - manager.InitializeWithDocument(old);
- -
- - // Act
- - var result = manager.CheckForStructureChangesAndWait(SourceChange);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Rejected | PartialParseResult.SpanContextChanged, result);
- - Assert.Equal(2, manager.ParseCount);
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsPrefixIdentifierReplacements_SingleSymbol()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var old = new StringTextSnapshot("foo @dTime baz");
- - var changed = new StringTextSnapshot("foo @DateTime baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(5, 1, old, 4, changed, "Date"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsPrefixIdentifierReplacements_MultipleSymbols()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var old = new StringTextSnapshot("foo @dTime.Now baz");
- - var changed = new StringTextSnapshot("foo @DateTime.Now baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(5, 1, old, 4, changed, "Date"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime.Now").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsSuffixIdentifierReplacements_SingleSymbol()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var old = new StringTextSnapshot("foo @Datet baz");
- - var changed = new StringTextSnapshot("foo @DateTime baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(9, 1, old, 4, changed, "Time"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsSuffixIdentifierReplacements_MultipleSymbols()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var old = new StringTextSnapshot("foo @DateTime.n baz");
- - var changed = new StringTextSnapshot("foo @DateTime.Now baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(14, 1, old, 3, changed, "Now"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime.Now").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsSurroundedIdentifierReplacements()
- - {
- - // Arrange
- - var factory = new SpanFactory();
- - var old = new StringTextSnapshot("foo @DateTime.n.ToString() baz");
- - var changed = new StringTextSnapshot("foo @DateTime.Now.ToString() baz");
- -
- - // Act and Assert
- - RunPartialParseTest(new TestEdit(14, 1, old, 3, changed, "Now"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("DateTime.Now.ToString()").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsDotlessCommitInsertionsInStatementBlockAfterIdentifiers()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateTime." + Environment.NewLine
- - + "}");
- - var old = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateTime" + Environment.NewLine
- - + "}");
- -
- - var edit = new TestEdit(15 + Environment.NewLine.Length, 0, old, 1, changed, ".");
- - using (var manager = CreateParserManager())
- - {
- - Action<TestEdit, PartialParseResult, string> applyAndVerifyPartialChange = (changeToApply, expectedResult, expectedCode) =>
- - {
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(expectedResult, result);
- - Assert.Equal(1, manager.ParseCount);
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root, new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.Code(Environment.NewLine + " ")
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code(expectedCode)
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Code(Environment.NewLine).AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - };
- -
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // This is the process of a dotless commit when doing "." insertions to commit intellisense changes.
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted, "DateTime.");
- -
- - old = changed;
- - changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateTime.." + Environment.NewLine
- - + "}");
- - edit = new TestEdit(16 + Environment.NewLine.Length, 0, old, 1, changed, ".");
- -
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted, "DateTime..");
- -
- - old = changed;
- - changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateTime.Now." + Environment.NewLine
- - + "}");
- - edit = new TestEdit(16 + Environment.NewLine.Length, 0, old, 3, changed, "Now");
- -
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted, "DateTime.Now.");
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsDotlessCommitInsertionsInStatementBlock()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateT." + Environment.NewLine
- - + "}");
- - var old = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateT" + Environment.NewLine
- - + "}");
- -
- - var edit = new TestEdit(12 + Environment.NewLine.Length, 0, old, 1, changed, ".");
- - using (var manager = CreateParserManager())
- - {
- - Action<TestEdit, PartialParseResult, string> applyAndVerifyPartialChange = (changeToApply, expectedResult, expectedCode) =>
- - {
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(expectedResult, result);
- - Assert.Equal(1, manager.ParseCount);
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root, new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.Code(Environment.NewLine + " ")
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code(expectedCode)
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Code(Environment.NewLine).AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - };
- -
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // This is the process of a dotless commit when doing "." insertions to commit intellisense changes.
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted, "DateT.");
- -
- - old = changed;
- - changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @DateTime." + Environment.NewLine
- - + "}");
- - edit = new TestEdit(12 + Environment.NewLine.Length, 0, old, 3, changed, "ime");
- -
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted, "DateTime.");
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionProvisionallyAcceptsDotlessCommitInsertions()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @DateT. baz");
- - var old = new StringTextSnapshot("foo @DateT baz");
- - var edit = new TestEdit(10, 0, old, 1, changed, ".");
- - using (var manager = CreateParserManager())
- - {
- - Action<TestEdit, PartialParseResult, string> applyAndVerifyPartialChange = (changeToApply, expectedResult, expectedCode) =>
- - {
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(expectedResult, result);
- - Assert.Equal(1, manager.ParseCount);
- -
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root, new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code(expectedCode).AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - };
- -
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // This is the process of a dotless commit when doing "." insertions to commit intellisense changes.
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateT.");
- -
- - old = changed;
- - changed = new StringTextSnapshot("foo @DateTime. baz");
- - edit = new TestEdit(10, 0, old, 3, changed, "ime");
- -
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateTime.");
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionProvisionallyAcceptsDotlessCommitInsertionsAfterIdentifiers()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @DateTime. baz");
- - var old = new StringTextSnapshot("foo @DateTime baz");
- - var edit = new TestEdit(13, 0, old, 1, changed, ".");
- - using (var manager = CreateParserManager())
- - {
- - Action<TestEdit, PartialParseResult, string> applyAndVerifyPartialChange = (changeToApply, expectedResult, expectedCode) =>
- - {
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(expectedResult, result);
- - Assert.Equal(1, manager.ParseCount);
- -
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root, new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code(expectedCode).AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - };
- -
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // This is the process of a dotless commit when doing "." insertions to commit intellisense changes.
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateTime.");
- -
- - old = changed;
- - changed = new StringTextSnapshot("foo @DateTime.. baz");
- - edit = new TestEdit(14, 0, old, 1, changed, ".");
- -
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateTime..");
- -
- - old = changed;
- - changed = new StringTextSnapshot("foo @DateTime.Now. baz");
- - edit = new TestEdit(14, 0, old, 3, changed, "Now");
- -
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateTime.Now.");
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionProvisionallyAcceptsCaseInsensitiveDotlessCommitInsertions_NewRoslynIntegration()
- - {
- - var factory = new SpanFactory();
- - var old = new StringTextSnapshot("foo @date baz");
- - var changed = new StringTextSnapshot("foo @date. baz");
- - var edit = new TestEdit(9, 0, old, 1, changed, ".");
- - using (var manager = CreateParserManager())
- - {
- - Action<TestEdit, PartialParseResult, string> applyAndVerifyPartialChange = (changeToApply, expectedResult, expectedCode) =>
- - {
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(expectedResult, result);
- - Assert.Equal(1, manager.ParseCount);
- -
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root, new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code(expectedCode).AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - };
- -
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // This is the process of a dotless commit when doing "." insertions to commit intellisense changes.
- -
- - // @date => @date.
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted | PartialParseResult.Provisional, "date.");
- -
- - old = changed;
- - changed = new StringTextSnapshot("foo @date baz");
- - edit = new TestEdit(9, 1, old, 0, changed, "");
- -
- - // @date. => @date
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted, "date");
- -
- - old = changed;
- - changed = new StringTextSnapshot("foo @DateTime baz");
- - edit = new TestEdit(5, 4, old, 8, changed, "DateTime");
- -
- - // @date => @DateTime
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted, "DateTime");
- -
- - old = changed;
- - changed = new StringTextSnapshot("foo @DateTime. baz");
- - edit = new TestEdit(13, 0, old, 1, changed, ".");
- -
- - // @DateTime => @DateTime.
- - applyAndVerifyPartialChange(edit, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateTime.");
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionProvisionallyAcceptsDeleteOfIdentifierPartsIfDotRemains()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @User. baz");
- - var old = new StringTextSnapshot("foo @User.Name baz");
- - RunPartialParseTest(new TestEdit(10, 4, old, 0, changed, string.Empty),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("User.").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")),
- - additionalFlags: PartialParseResult.Provisional);
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsDeleteOfIdentifierPartsIfSomeOfIdentifierRemains()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @Us baz");
- - var old = new StringTextSnapshot("foo @User baz");
- - RunPartialParseTest(new TestEdit(7, 2, old, 0, changed, string.Empty),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("Us").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionProvisionallyAcceptsMultipleInsertionIfItCausesIdentifierExpansionAndTrailingDot()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @User. baz");
- - var old = new StringTextSnapshot("foo @U baz");
- - RunPartialParseTest(new TestEdit(6, 0, old, 4, changed, "ser."),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("User.").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")),
- - additionalFlags: PartialParseResult.Provisional);
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsMultipleInsertionIfItOnlyCausesIdentifierExpansion()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @barbiz baz");
- - var old = new StringTextSnapshot("foo @bar baz");
- - RunPartialParseTest(new TestEdit(8, 0, old, 3, changed, "biz"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("barbiz").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" baz")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsIdentifierExpansionAtEndOfNonWhitespaceCharacters()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @food" + Environment.NewLine
- - + "}");
- - var old = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @foo" + Environment.NewLine
- - + "}");
- - RunPartialParseTest(new TestEdit(10 + Environment.NewLine.Length, 0, old, 1, changed, "d"),
- - new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.Code(Environment.NewLine + " ")
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("food")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Code(Environment.NewLine).AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsIdentifierAfterDotAtEndOfNonWhitespaceCharacters()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @foo.d" + Environment.NewLine
- - + "}");
- - var old = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @foo." + Environment.NewLine
- - + "}");
- - RunPartialParseTest(new TestEdit(11 + Environment.NewLine.Length, 0, old, 1, changed, "d"),
- - new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.Code(Environment.NewLine + " ")
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foo.d")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Code(Environment.NewLine).AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsDotAtEndOfNonWhitespaceCharacters()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @foo." + Environment.NewLine
- - + "}");
- - var old = new StringTextSnapshot("@{" + Environment.NewLine
- - + " @foo" + Environment.NewLine
- - + "}");
- - RunPartialParseTest(new TestEdit(10 + Environment.NewLine.Length, 0, old, 1, changed, "."),
- - new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.Code(Environment.NewLine + " ")
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code(@"foo.")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Code(Environment.NewLine).AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionRejectsChangeWhichWouldHaveBeenAcceptedIfLastChangeWasProvisionallyAcceptedOnDifferentSpan()
- - {
- - var factory = new SpanFactory();
- -
- - // Arrange
- - var dotTyped = new TestEdit(8, 0, new StringTextSnapshot("foo @foo @bar"), 1, new StringTextSnapshot("foo @foo. @bar"), ".");
- - var charTyped = new TestEdit(14, 0, new StringTextSnapshot("foo @foo. @bar"), 1, new StringTextSnapshot("foo @foo. @barb"), "b");
- - using (var manager = CreateParserManager())
- - {
- - manager.InitializeWithDocument(dotTyped.OldSnapshot);
- -
- - // Apply the dot change
- - Assert.Equal(PartialParseResult.Provisional | PartialParseResult.Accepted, manager.CheckForStructureChangesAndWait(dotTyped));
- -
- - // Act (apply the identifier start char change)
- - var result = manager.CheckForStructureChangesAndWait(charTyped);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Rejected, result);
- - Assert.False(manager.Parser.LastResultProvisional, "LastResultProvisional flag should have been cleared but it was not");
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root,
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foo")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(". "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("barb")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.EmptyHtml()));
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsIdentifierTypedAfterDotIfLastChangeWasProvisionalAcceptanceOfDot()
- - {
- - var factory = new SpanFactory();
- -
- - // Arrange
- - var dotTyped = new TestEdit(8, 0, new StringTextSnapshot("foo @foo bar"), 1, new StringTextSnapshot("foo @foo. bar"), ".");
- - var charTyped = new TestEdit(9, 0, new StringTextSnapshot("foo @foo. bar"), 1, new StringTextSnapshot("foo @foo.b bar"), "b");
- - using (var manager = CreateParserManager())
- - {
- - manager.InitializeWithDocument(dotTyped.OldSnapshot);
- -
- - // Apply the dot change
- - Assert.Equal(PartialParseResult.Provisional | PartialParseResult.Accepted, manager.CheckForStructureChangesAndWait(dotTyped));
- -
- - // Act (apply the identifier start char change)
- - var result = manager.CheckForStructureChangesAndWait(charTyped);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Accepted, result);
- - Assert.False(manager.Parser.LastResultProvisional, "LastResultProvisional flag should have been cleared but it was not");
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root,
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foo.b")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" bar")));
- - }
- - }
- -
- - [Fact]
- - public void ImplicitExpressionProvisionallyAcceptsDotAfterIdentifierInMarkup()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @foo. bar");
- - var old = new StringTextSnapshot("foo @foo bar");
- - RunPartialParseTest(new TestEdit(8, 0, old, 1, changed, "."),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foo.")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" bar")),
- - additionalFlags: PartialParseResult.Provisional);
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsAdditionalIdentifierCharactersIfEndOfSpanIsIdentifier()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("foo @foob bar");
- - var old = new StringTextSnapshot("foo @foo bar");
- - RunPartialParseTest(new TestEdit(8, 0, old, 1, changed, "b"),
- - new MarkupBlock(
- - factory.Markup("foo "),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foob")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.Markup(" bar")));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsAdditionalIdentifierStartCharactersIfEndOfSpanIsDot()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{@foo.b}");
- - var old = new StringTextSnapshot("@{@foo.}");
- - RunPartialParseTest(new TestEdit(7, 0, old, 1, changed, "b"),
- - new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.EmptyCSharp()
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foo.b")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.EmptyCSharp().AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionAcceptsDotIfTrailingDotsAreAllowed()
- - {
- - var factory = new SpanFactory();
- - var changed = new StringTextSnapshot("@{@foo.}");
- - var old = new StringTextSnapshot("@{@foo}");
- - RunPartialParseTest(new TestEdit(6, 0, old, 1, changed, "."),
- - new MarkupBlock(
- - factory.EmptyHtml(),
- - new StatementBlock(
- - factory.CodeTransition(),
- - factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- - factory.EmptyCSharp()
- - .AsStatement()
- - .AutoCompleteWith(autoCompleteString: null),
- - new ExpressionBlock(
- - factory.CodeTransition(),
- - factory.Code("foo.")
- - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- - factory.EmptyCSharp().AsStatement(),
- - factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- - factory.EmptyHtml()));
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfIfKeywordTyped()
- - {
- - RunTypeKeywordTest("if");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfDoKeywordTyped()
- - {
- - RunTypeKeywordTest("do");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfTryKeywordTyped()
- - {
- - RunTypeKeywordTest("try");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfForKeywordTyped()
- - {
- - RunTypeKeywordTest("for");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfForEachKeywordTyped()
- - {
- - RunTypeKeywordTest("foreach");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfWhileKeywordTyped()
- - {
- - RunTypeKeywordTest("while");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfSwitchKeywordTyped()
- - {
- - RunTypeKeywordTest("switch");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfLockKeywordTyped()
- - {
- - RunTypeKeywordTest("lock");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfUsingKeywordTyped()
- - {
- - RunTypeKeywordTest("using");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfSectionKeywordTyped()
- - {
- - RunTypeKeywordTest("section");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfInheritsKeywordTyped()
- - {
- - RunTypeKeywordTest("inherits");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfFunctionsKeywordTyped()
- - {
- - RunTypeKeywordTest("functions");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfNamespaceKeywordTyped()
- - {
- - RunTypeKeywordTest("namespace");
- - }
- -
- - [Fact]
- - public void ImplicitExpressionCorrectlyTriggersReparseIfClassKeywordTyped()
- - {
- - RunTypeKeywordTest("class");
- - }
- -
- - private static TestEdit CreateInsertionChange(string initialText, int insertionLocation, string insertionText)
- - {
- - var changedText = initialText.Insert(insertionLocation, insertionText);
- - var sourceChange = new SourceChange(insertionLocation, 0, insertionText);
- - var oldSnapshot = new StringTextSnapshot(initialText);
- - var changedSnapshot = new StringTextSnapshot(changedText);
- - return new TestEdit
- - {
- - Change = sourceChange,
- - OldSnapshot = oldSnapshot,
- - NewSnapshot = changedSnapshot,
- - };
- - }
- -
- - private static void RunFullReparseTest(TestEdit edit, PartialParseResult additionalFlags = (PartialParseResult)0)
- - {
- - // Arrange
- - using (var manager = CreateParserManager())
- - {
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // Act
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Rejected | additionalFlags, result);
- - Assert.Equal(2, manager.ParseCount);
- - }
- - }
- -
- - private static void RunPartialParseTest(TestEdit edit, Block newTreeRoot, PartialParseResult additionalFlags = (PartialParseResult)0)
- - {
- - // Arrange
- - using (var manager = CreateParserManager())
- - {
- - manager.InitializeWithDocument(edit.OldSnapshot);
- -
- - // Act
- - var result = manager.CheckForStructureChangesAndWait(edit);
- -
- - // Assert
- - Assert.Equal(PartialParseResult.Accepted | additionalFlags, result);
- - Assert.Equal(1, manager.ParseCount);
- - ParserTestBase.EvaluateParseTree(manager.Parser.CurrentSyntaxTree.Root, newTreeRoot);
- - }
- - }
- -
- - private static TestParserManager CreateParserManager()
- - {
- - var parser = new RazorEditorParser(CreateTemplateEngine(), TestLinePragmaFileName);
- - return new TestParserManager(parser);
- - }
- -
- - private static RazorTemplateEngine CreateTemplateEngine(
- - string path = TestLinePragmaFileName,
- - IEnumerable<TagHelperDescriptor> tagHelpers = null)
- - {
- - var engine = RazorEngine.CreateDesignTime(builder =>
- - {
- - RazorExtensions.Register(builder);
- -
- - if (tagHelpers != null)
- - {
- - builder.AddTagHelpers(tagHelpers);
- - }
- - });
- -
- - // GetImports on RazorTemplateEngine will at least check that the item exists, so we need to pretend
- - // that it does.
- - var items = new List<RazorProjectItem>();
- - items.Add(new TestRazorProjectItem(path));
- -
- - var project = new TestRazorProject(items);
- -
- - var templateEngine = new RazorTemplateEngine(engine, project);
- - templateEngine.Options.DefaultImports = RazorSourceDocument.Create("@addTagHelper *, Test", "_TestImports.cshtml");
- - return templateEngine;
- - }
- -
- - private static void RunTypeKeywordTest(string keyword)
- - {
- - var before = "@" + keyword.Substring(0, keyword.Length - 1);
- - var after = "@" + keyword;
- - var changed = new StringTextSnapshot(after);
- - var old = new StringTextSnapshot(before);
- - var change = new SourceChange(keyword.Length, 0, keyword[keyword.Length - 1].ToString());
- - var edit = new TestEdit
- - {
- - Change = change,
- - NewSnapshot = changed,
- - OldSnapshot = old
- - };
- - RunFullReparseTest(edit, additionalFlags: PartialParseResult.SpanContextChanged);
- - }
- -
- - private static void DoWithTimeoutIfNotDebugging(Func<int, bool> withTimeout)
- - {
- -#if DEBUG
- - if (Debugger.IsAttached)
- - {
- - withTimeout(Timeout.Infinite);
- - }
- - else
- - {
- -#endif
- - Assert.True(withTimeout((int)TimeSpan.FromSeconds(1).TotalMilliseconds), "Timeout expired!");
- -#if DEBUG
- - }
- -#endif
- - }
- -
- - private class TestParserManager : IDisposable
- - {
- - public int ParseCount;
- -
- - private readonly ManualResetEventSlim _parserComplete;
- -
- - public TestParserManager(RazorEditorParser parser)
- - {
- - _parserComplete = new ManualResetEventSlim();
- - ParseCount = 0;
- - Parser = parser;
- - parser.DocumentParseComplete += (sender, args) =>
- - {
- - Interlocked.Increment(ref ParseCount);
- - _parserComplete.Set();
- - };
- - }
- -
- - public RazorEditorParser Parser { get; }
- -
- - public void InitializeWithDocument(ITextSnapshot snapshot)
- - {
- - var initialChange = new SourceChange(0, 0, string.Empty);
- - var edit = new TestEdit
- - {
- - Change = initialChange,
- - OldSnapshot = snapshot,
- - NewSnapshot = snapshot
- - };
- - CheckForStructureChangesAndWait(edit);
- - }
- -
- - public PartialParseResult CheckForStructureChangesAndWait(TestEdit edit)
- - {
- - var result = Parser.CheckForStructureChanges(edit.Change, edit.NewSnapshot);
- - if (result.HasFlag(PartialParseResult.Rejected))
- - {
- - WaitForParse();
- - }
- - return result;
- - }
- -
- - public void WaitForParse()
- - {
- - DoWithTimeoutIfNotDebugging(_parserComplete.Wait); // Wait for the parse to finish
- - _parserComplete.Reset();
- - }
- -
- - public void Dispose()
- - {
- - Parser.Dispose();
- - }
- - }
- -
- - private class TestEdit
- - {
- - public TestEdit()
- - {
- - }
- -
- - public TestEdit(int position, int oldLength, ITextSnapshot oldSnapshot, int newLength, ITextSnapshot newSnapshot, string newText)
- - {
- - Change = new SourceChange(position, oldLength, newText);
- - OldSnapshot = oldSnapshot;
- - NewSnapshot = newSnapshot;
- - }
- -
- - public SourceChange Change { get; set; }
- -
- - public ITextSnapshot OldSnapshot { get; set; }
- -
- - public ITextSnapshot NewSnapshot { get; set; }
- - }
- - }
- -}
- \ No newline at end of file
|