1313use Symfony \Lsp \Feature \Environment \EnvironmentIndexRegistry ;
1414use Symfony \Lsp \Feature \Environment \EnvironmentProvider ;
1515use Symfony \Lsp \Parser \Php \PhpCommentParser ;
16+ use Symfony \Lsp \Parser \TreeSitter \NativeTreeSitterParser ;
17+ use Symfony \Lsp \Parser \TreeSitter \TreeSitterResultDecoder ;
1618use Symfony \Lsp \Parser \Twig \TwigCommentParser ;
1719use Symfony \Lsp \Parser \Xml \XmlCommentParser ;
18- use Symfony \Lsp \Parser \Yaml \YamlCommentParser ;
20+ use Symfony \Lsp \Parser \Yaml \YamlDocumentParser ;
1921use Symfony \Lsp \Project \Project ;
2022use Symfony \Lsp \Project \ProjectRegistry ;
2123use Symfony \Lsp \Project \UriToPathConverter ;
@@ -25,7 +27,7 @@ final class EnvironmentProviderTest extends TestCase
2527{
2628 public function testIndexesNamesAndReferencesWithoutValues (): void
2729 {
28- $ extractor = new EnvironmentExtractor (new PositionConverter (), new UriToPathConverter (), new TwigCommentParser (), new PhpCommentParser (), new YamlCommentParser (), new XmlCommentParser ());
30+ $ extractor = new EnvironmentExtractor (new PositionConverter (), new UriToPathConverter (), new TwigCommentParser (), new PhpCommentParser (), $ this -> yamlParser (), new XmlCommentParser ());
2931 $ facts = $ extractor ->extract ('file:///workspace/.env ' , 'dotenv ' , "APP_SECRET=CANARY_SECRET_VALUE \nAPP_URL=https://example.com \nEMPTY= \nCHILD= \${APP_URL:- \${FALLBACK_URL}}/ \$EMPTY \nPARTIAL= \${UNFINISHED \nESCAPED= \\\$IGNORED \n" );
3032
3133 self ::assertSame (['APP_SECRET ' , 'APP_URL ' , 'EMPTY ' , 'CHILD ' , 'PARTIAL ' , 'ESCAPED ' ], array_map (static fn ($ item ): string => $ item ->name , $ facts ->declarations ));
@@ -48,15 +50,15 @@ public function testSupportsEnvironmentExpressionsInYamlScalarContexts(string $t
4850 $ converter = new PositionConverter ();
4951 $ twigComments = new TwigCommentParser ();
5052 $ phpComments = new PhpCommentParser ();
51- $ yamlComments = new YamlCommentParser ();
53+ $ yamlParser = $ this -> yamlParser ();
5254 $ xmlComments = new XmlCommentParser ();
53- $ extractor = new EnvironmentExtractor ($ converter , new UriToPathConverter (), $ twigComments , $ phpComments , $ yamlComments , $ xmlComments );
55+ $ extractor = new EnvironmentExtractor ($ converter , new UriToPathConverter (), $ twigComments , $ phpComments , $ yamlParser , $ xmlComments );
5456 $ indexes = new EnvironmentIndexRegistry ();
5557 $ indexes ->forProject ($ project )->replaceSources (
5658 $ extractor ->extract ('file:///workspace/.env ' , 'dotenv ' , "PARTIAL_ENV=value \n" ),
5759 $ extractor ->extract ($ uri , 'yaml ' , $ text ),
5860 );
59- $ provider = new EnvironmentProvider (new DocumentContextResolver ($ documents , $ projects ), $ converter , new LspProtocolMapper (), $ indexes , $ extractor , $ twigComments , $ phpComments , $ yamlComments , $ xmlComments );
61+ $ provider = new EnvironmentProvider (new DocumentContextResolver ($ documents , $ projects ), $ converter , new LspProtocolMapper (), $ indexes , $ extractor , $ twigComments , $ phpComments , $ yamlParser , $ xmlComments );
6062
6163 $ facts = $ extractor ->extract ($ uri , 'yaml ' , $ text );
6264 self ::assertSame (['COMPLETE_ENV ' ], array_map (static fn ($ reference ): string => $ reference ->name , $ facts ->references ));
@@ -118,13 +120,13 @@ public function testCompletesHoversNavigatesAndDiagnosesProcessors(): void
118120 $converter = new PositionConverter();
119121 $commentParser = new TwigCommentParser();
120122 $phpComments = new PhpCommentParser();
121- $yamlComments = new YamlCommentParser ();
123+ $yamlParser = $this->yamlParser ();
122124 $xmlComments = new XmlCommentParser();
123- $extractor = new EnvironmentExtractor($converter, new UriToPathConverter(), $commentParser, $phpComments, $yamlComments , $xmlComments);
125+ $extractor = new EnvironmentExtractor($converter, new UriToPathConverter(), $commentParser, $phpComments, $yamlParser , $xmlComments);
124126 $indexes = new EnvironmentIndexRegistry();
125127 $indexes->forProject($project)->replaceSources($extractor->extract('file:///workspace/.env', 'dotenv', "APP_URL=CANARY_SECRET_VALUE\n"), $extractor->extract($uri, 'yaml', $text));
126128 $indexes->forProject($project)->replaceProcessors(['custom' => 'string', 'json' => 'array']);
127- $provider = new EnvironmentProvider(new DocumentContextResolver($documents, $projects), $converter, new LspProtocolMapper(), $indexes, $extractor, $commentParser, $phpComments, $yamlComments , $xmlComments);
129+ $provider = new EnvironmentProvider(new DocumentContextResolver($documents, $projects), $converter, new LspProtocolMapper(), $indexes, $extractor, $commentParser, $phpComments, $yamlParser , $xmlComments);
128130 $position = $converter->toPosition($text, strpos($text, 'APP_UR') + \strlen('APP_UR'));
129131 $params = ['textDocument' => ['uri' => $uri], 'position' => ['line' => $position->line, 'character' => $position->character]];
130132
@@ -162,16 +164,16 @@ public function testIgnoresCommentedConfigurationAcrossCapabilities(string $lang
162164 $converter = new PositionConverter();
163165 $twigComments = new TwigCommentParser();
164166 $phpComments = new PhpCommentParser();
165- $yamlComments = new YamlCommentParser ();
167+ $yamlParser = $this->yamlParser ();
166168 $xmlComments = new XmlCommentParser();
167- $extractor = new EnvironmentExtractor($converter, new UriToPathConverter(), $twigComments, $phpComments, $yamlComments , $xmlComments);
169+ $extractor = new EnvironmentExtractor($converter, new UriToPathConverter(), $twigComments, $phpComments, $yamlParser , $xmlComments);
168170 $indexes = new EnvironmentIndexRegistry();
169171 $indexes->forProject($project)->replaceSources(
170172 $extractor->extract('file:///workspace/.env', 'dotenv', "APP_URL=value\n"),
171173 $extractor->extract($uri, $languageId, $text),
172174 );
173175 $indexes->forProject($project)->replaceProcessors(['json' => 'array']);
174- $provider = new EnvironmentProvider(new DocumentContextResolver($documents, $projects), $converter, new LspProtocolMapper(), $indexes, $extractor, $twigComments, $phpComments, $yamlComments , $xmlComments);
176+ $provider = new EnvironmentProvider(new DocumentContextResolver($documents, $projects), $converter, new LspProtocolMapper(), $indexes, $extractor, $twigComments, $phpComments, $yamlParser , $xmlComments);
175177
176178 $commentCompletionOffset = strpos($text, 'APP_UR') + \strlen('APP_UR');
177179 self::assertNull($provider->complete($this->positionParams($converter, $uri, $text, $commentCompletionOffset)));
@@ -233,12 +235,12 @@ public function testOffersNoEnvironmentCompletionsInsidePhpComments(): void
233235 $converter = new PositionConverter();
234236 $commentParser = new TwigCommentParser();
235237 $phpComments = new PhpCommentParser();
236- $yamlComments = new YamlCommentParser ();
238+ $yamlParser = $this->yamlParser ();
237239 $xmlComments = new XmlCommentParser();
238- $extractor = new EnvironmentExtractor($converter, new UriToPathConverter(), $commentParser, $phpComments, $yamlComments , $xmlComments);
240+ $extractor = new EnvironmentExtractor($converter, new UriToPathConverter(), $commentParser, $phpComments, $yamlParser , $xmlComments);
239241 $indexes = new EnvironmentIndexRegistry();
240242 $indexes->forProject($project)->replaceSources($extractor->extract('file:///workspace/.env', 'dotenv', "APP_URL=value\n"));
241- $provider = new EnvironmentProvider(new DocumentContextResolver($documents, $projects), $converter, new LspProtocolMapper(), $indexes, $extractor, $commentParser, $phpComments, $yamlComments , $xmlComments);
243+ $provider = new EnvironmentProvider(new DocumentContextResolver($documents, $projects), $converter, new LspProtocolMapper(), $indexes, $extractor, $commentParser, $phpComments, $yamlParser , $xmlComments);
242244 $completionOffset = strpos($text, 'APP_U') + \strlen('APP_U');
243245 $position = $converter->toPosition($text, $completionOffset);
244246
@@ -251,7 +253,7 @@ public function testOffersNoEnvironmentCompletionsInsidePhpComments(): void
251253
252254 public function testIgnoresEnvironmentReferencesInPhpComments(): void
253255 {
254- $extractor = new EnvironmentExtractor(new PositionConverter(), new UriToPathConverter(), new TwigCommentParser(), new PhpCommentParser(), new YamlCommentParser (), new XmlCommentParser());
256+ $extractor = new EnvironmentExtractor(new PositionConverter(), new UriToPathConverter(), new TwigCommentParser(), new PhpCommentParser(), $this->yamlParser (), new XmlCommentParser());
255257
256258 $facts = $extractor->extract('file:///workspace/src/Kernel.php', 'php', <<<'PHP'
257259 <?php
@@ -263,6 +265,11 @@ public function testIgnoresEnvironmentReferencesInPhpComments(): void
263265 self::assertSame(['LIVE_ENV'], array_map(static fn ($reference): string => $reference->name, $facts->references));
264266 }
265267
268+ private function yamlParser(): YamlDocumentParser
269+ {
270+ return new YamlDocumentParser(new NativeTreeSitterParser(new TreeSitterResultDecoder()));
271+ }
272+
266273 /** @return array{textDocument: array{uri: string}, position: array{line: int, character: int}} */
267274 private function positionParams(PositionConverter $converter, string $uri, string $text, int $offset): array
268275 {
0 commit comments