Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change format of requests to show module sources #12351

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix local modules
  • Loading branch information
Stephen Weatherford authored and Stephen Weatherford committed Nov 4, 2023
commit e30d4615f7d3a96c7fd397d5dc0bea382246dab2
17 changes: 7 additions & 10 deletions src/Bicep.LangServer/Handlers/BicepDefinitionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ private LocationOrLocationLinks HandleUnboundSymbolLocation(DefinitionParams req
&& matchingNodes[^3] is ModuleDeclarationSyntax moduleDeclarationSyntax
&& matchingNodes[^2] is StringSyntax stringToken
&& context.Compilation.SourceFileGrouping.TryGetSourceFile(moduleDeclarationSyntax).IsSuccess(out var sourceFile)
&& this.moduleDispatcher.TryGetArtifactReference(moduleDeclarationSyntax, request.TextDocument.Uri.ToUriEncoded()).IsSuccess(out var artifactReference)
&& artifactReference is OciArtifactReference moduleReference)
&& this.moduleDispatcher.TryGetArtifactReference(moduleDeclarationSyntax, request.TextDocument.Uri.ToUriEncoded()).IsSuccess(out var moduleReference))
{
return HandleModuleReference(context, stringToken, sourceFile, moduleReference);
}
Expand All @@ -135,8 +134,7 @@ private LocationOrLocationLinks HandleUnboundSymbolLocation(DefinitionParams req
&& matchingNodes[^4] is CompileTimeImportDeclarationSyntax importDeclarationSyntax
&& matchingNodes[^2] is StringSyntax stringToken
&& context.Compilation.SourceFileGrouping.TryGetSourceFile(importDeclarationSyntax).IsSuccess(out var sourceFile)
&& this.moduleDispatcher.TryGetArtifactReference(importDeclarationSyntax, request.TextDocument.Uri.ToUriEncoded()).IsSuccess(out var artifactReference)
&& artifactReference is OciArtifactReference moduleReference)
&& this.moduleDispatcher.TryGetArtifactReference(importDeclarationSyntax, request.TextDocument.Uri.ToUriEncoded()).IsSuccess(out var moduleReference))
{
// goto beginning of the module file.
return GetFileDefinitionLocation(
Expand Down Expand Up @@ -181,7 +179,7 @@ private LocationOrLocationLinks HandleUnboundSymbolLocation(DefinitionParams req
return new();
}

private LocationOrLocationLinks HandleModuleReference(CompilationContext context, StringSyntax stringToken, ISourceFile sourceFile, OciArtifactReference reference)
private LocationOrLocationLinks HandleModuleReference(CompilationContext context, StringSyntax stringToken, ISourceFile sourceFile, ArtifactReference reference)
{
// Return the correct link format so our language client can display the sources
return GetFileDefinitionLocation(
Expand All @@ -191,23 +189,22 @@ private LocationOrLocationLinks HandleModuleReference(CompilationContext context
new() { Start = new(0, 0), End = new(0, 0) });
}

private Uri GetModuleSourceLinkUri(ISourceFile sourceFile, OciArtifactReference reference)
private Uri GetModuleSourceLinkUri(ISourceFile sourceFile, ArtifactReference reference)
{
if (!this.CanClientAcceptRegistryContent() || !reference.IsExternal)
if (!this.CanClientAcceptRegistryContent() || !reference.IsExternal || reference is not OciArtifactReference ociReference)
{
// the client doesn't support the bicep-extsrc scheme or we're dealing with a local module
// just use the file URI
return sourceFile.FileUri;
}

return BicepExternalSourceRequestHandler.GetExternalSourceLinkUri(reference, moduleDispatcher.TryGetModuleSources(reference));
return BicepExternalSourceRequestHandler.GetExternalSourceLinkUri(ociReference, moduleDispatcher.TryGetModuleSources(reference));
}

private LocationOrLocationLinks HandleWildcardImportDeclaration(CompilationContext context, DefinitionParams request, SymbolResolutionResult result, WildcardImportSymbol wildcardImport)
{
if (context.Compilation.SourceFileGrouping.TryGetSourceFile(wildcardImport.EnclosingDeclaration).IsSuccess(out var sourceFile) &&
wildcardImport.TryGetArtifactReference().IsSuccess(out var artifactReference)
&& artifactReference is OciArtifactReference moduleReference)
wildcardImport.TryGetArtifactReference().IsSuccess(out var moduleReference))
{
return GetFileDefinitionLocation(
GetModuleSourceLinkUri(sourceFile, moduleReference),
Expand Down
Loading