Skip to content

Commit

Permalink
Encoding DocumentUri.Path when converting DocumentUri to Uri (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shenglol authored Aug 29, 2023
1 parent d4a130b commit e0ce74d
Show file tree
Hide file tree
Showing 42 changed files with 188 additions and 134 deletions.
2 changes: 2 additions & 0 deletions src/BannedSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ M:System.Console.WriteLine(System.Decimal);Don't use Console.WriteLine for loggi

M:Moq.Mock`1.#ctor();Don't use the default Mock constructor. Set Strict mode explicitly or use a MockRepository set to strict mode.
M:Moq.Mock`1.#ctor(System.Object[]);Don't use the default Mock constructor. Set Strict mode explicitly or use a MockRepository set to strict mode.

M:OmniSharp.Extensions.LanguageServer.Protocol.DocumentUri.ToUri();Use DocumentUri.ToUriEncoded() instead.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void GetAllDiagnostics_VerifyDisableNextLineDiagnosticsDirectiveDoesNotSu
resource test";
var bicepFilePath = FileHelper.SaveResultFile(TestContext, "main.bicep", bicepFileContents);
var documentUri = DocumentUri.FromFileSystemPath(bicepFilePath);
var uri = documentUri.ToUri();
var uri = documentUri.ToUriEncoded();

var files = new Dictionary<Uri, string>
{
Expand Down Expand Up @@ -243,7 +243,7 @@ public void GetAllDiagnostics_VerifyDisableNextLineDiagnosticsDirectiveSupportsC
}";
var bicepFilePath = FileHelper.SaveResultFile(TestContext, "main.bicep", bicepFileContents);
var documentUri = DocumentUri.FromFileSystemPath(bicepFilePath);
var uri = documentUri.ToUri();
var uri = documentUri.ToUriEncoded();

var files = new Dictionary<Uri, string>
{
Expand All @@ -262,7 +262,7 @@ public void GetAllDiagnostics_VerifyDisableNextLineDiagnosticsDirectiveSupportsL
param storageAccount string = 'testStorageAccount'";
var bicepFilePath = FileHelper.SaveResultFile(TestContext, "main.bicep", bicepFileContents);
var documentUri = DocumentUri.FromFileSystemPath(bicepFilePath);
var uri = documentUri.ToUri();
var uri = documentUri.ToUriEncoded();

var files = new Dictionary<Uri, string>
{
Expand All @@ -282,7 +282,7 @@ public void GetAllDiagnostics_WithNoDisableNextLineDiagnosticsDirectiveInPreviou
param storageAccount string = 'testStorageAccount'";
var bicepFilePath = FileHelper.SaveResultFile(TestContext, "main.bicep", bicepFileContents);
var documentUri = DocumentUri.FromFileSystemPath(bicepFilePath);
var uri = documentUri.ToUri();
var uri = documentUri.ToUriEncoded();

var files = new Dictionary<Uri, string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public async Task GetDescription_WithValidDescriptionAndDocumentationUriInManife
{
string testOutputPath = FileHelper.GetUniqueTestOutputPath(TestContext);
var bicepPath = FileHelper.SaveResultFile(TestContext, "input.bicep", bicepFileContents, testOutputPath);
var parentModuleUri = DocumentUri.FromFileSystemPath(bicepPath).ToUri();
var parentModuleUri = DocumentUri.FromFileSystemPath(bicepPath).ToUriEncoded();

var ociArtifactModuleReference = OciArtifactModuleReferenceHelper.GetModuleReferenceAndSaveManifestFile(
TestContext,
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.LangServer.IntegrationTests/BicepConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public async Task WithMultipleConfigFiles_ShouldUseConfigSettingsFromRelevantDir

string bicepFileContents = @"param storageAccountName string = 'test'";
var documentUriOfFileInChildDirectory = SaveFile("main.bicep", bicepFileContents, childDirectoryPath);
var uriOfFileInChildDirectory = documentUriOfFileInChildDirectory.ToUri();
var uriOfFileInChildDirectory = documentUriOfFileInChildDirectory.ToUriEncoded();

// open the main document and verify diagnostics
{
Expand All @@ -511,7 +511,7 @@ await VerifyDiagnosticsAsync(diagsListener, uriOfFileInChildDirectory, (@"Parame
// add bicepconfig.json to parent directory and verify diagnostics
{
var documentUriOfFileInParentDirectory = SaveFile("main.bicep", bicepFileContents, parentDirectoryPath);
var uriOfFileInParentDirectory = documentUriOfFileInParentDirectory.ToUri();
var uriOfFileInParentDirectory = documentUriOfFileInParentDirectory.ToUriEncoded();

bicepConfigFileContents = @"{
""analyzers"": {
Expand Down
8 changes: 4 additions & 4 deletions src/Bicep.LangServer.IntegrationTests/CodeActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ private async Task VerifyCodeActionIsAvailableToSuppressLinterDiagnostics(string
var bicepFileContents = @"param storageAccount string = 'testStorageAccount'";
var bicepFilePath = FileHelper.SaveResultFile(TestContext, "main.bicep", bicepFileContents, testOutputPath);
var documentUri = DocumentUri.FromFileSystemPath(bicepFilePath);
var uri = documentUri.ToUri();
var uri = documentUri.ToUriEncoded();

var fileSystemDict = new Dictionary<Uri, string>();
fileSystemDict[uri] = bicepFileContents;

string bicepConfigFilePath = FileHelper.SaveResultFile(TestContext, "bicepconfig.json", bicepConfigFileContents, testOutputPath);
var bicepConfigUri = DocumentUri.FromFileSystemPath(bicepConfigFilePath);
fileSystemDict[bicepConfigUri.ToUri()] = bicepConfigFileContents;
fileSystemDict[bicepConfigUri.ToUriEncoded()] = bicepConfigFileContents;

var compilation = Services.BuildCompilation(fileSystemDict, uri);
var diagnostics = compilation.GetEntrypointSemanticModel().GetAllDiagnostics();
Expand Down Expand Up @@ -271,7 +271,7 @@ public async Task VerifyCodeActionIsNotAvailableToSuppressCoreCompilerError()
resource test";
var bicepFilePath = FileHelper.SaveResultFile(TestContext, "main.bicep", bicepFileContents);
var documentUri = DocumentUri.FromFileSystemPath(bicepFilePath);
var uri = documentUri.ToUri();
var uri = documentUri.ToUriEncoded();

var files = new Dictionary<Uri, string>
{
Expand Down Expand Up @@ -333,7 +333,7 @@ public async Task VerifyCodeActionIsAvailableToSuppressCoreCompilerWarning()
}";
var bicepFilePath = FileHelper.SaveResultFile(TestContext, "main.bicep", bicepFileContents);
var documentUri = DocumentUri.FromFileSystemPath(bicepFilePath);
var uri = documentUri.ToUri();
var uri = documentUri.ToUriEncoded();

var files = new Dictionary<Uri, string>
{
Expand Down
10 changes: 5 additions & 5 deletions src/Bicep.LangServer.IntegrationTests/CompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public async Task ValidateSnippetCompletionAfterPlaceholderReplacements(Completi
private async Task<string> RequestSnippetCompletion(string bicepFileName, CompletionData completionData, string placeholderFile, int cursor)
{
var documentUri = DocumentUri.FromFileSystemPath(bicepFileName);
var bicepFile = SourceFileFactory.CreateBicepFile(documentUri.ToUri(), placeholderFile);
var bicepFile = SourceFileFactory.CreateBicepFile(documentUri.ToUriEncoded(), placeholderFile);

var helper = await ServerWithNamespaceProvider.GetAsync();
await helper.OpenFileOnceAsync(this.TestContext, placeholderFile, documentUri);
Expand Down Expand Up @@ -3850,7 +3850,7 @@ public async Task ModuleRegistryReferenceCompletions_GetCompletionsAfterBrSchema
.AddSingleton<ISettingsProvider>(settingsProvider.Object)
.WithFileResolver(new FileResolver(new IOFileSystem())));

var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUri(), text);
var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUriEncoded(), text);
var completions = await file.RequestCompletion(cursor);

completions.Count().Should().Be(3);
Expand Down Expand Up @@ -3879,7 +3879,7 @@ public async Task ModuleRegistryReferenceCompletions_GetCompletionsForFolderInsi
.AddSingleton<ISettingsProvider>(settingsProvider.Object)
.WithFileResolver(new FileResolver(new IOFileSystem())));

var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUri(), text);
var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUriEncoded(), text);
var completions = await file.RequestCompletion(cursor);

completions.Count().Should().Be(2);
Expand Down Expand Up @@ -3915,7 +3915,7 @@ public async Task ModuleRegistryReferenceCompletions_GetPathCompletions(string i
.AddSingleton<ISettingsProvider>(settingsProvider.Object)
.WithFileResolver(new FileResolver(new IOFileSystem())));

var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUri(), text);
var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUriEncoded(), text);
var completions = await file.RequestCompletion(cursor);

completions.Count().Should().Be(2);
Expand Down Expand Up @@ -3949,7 +3949,7 @@ public async Task ModuleRegistryReferenceCompletions_GetVersionCompletions(strin
.AddSingleton<ISettingsProvider>(settingsProvider.Object)
.WithFileResolver(new FileResolver(new IOFileSystem())));

var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUri(), text);
var file = await new ServerRequestHelper(TestContext, helper).OpenFile(mainUri.ToUriEncoded(), text);
var completions = await file.RequestCompletion(cursor);

completions.Count().Should().Be(2);
Expand Down
10 changes: 5 additions & 5 deletions src/Bicep.LangServer.IntegrationTests/DeploymentGraphTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task RequestDeploymentGraphShouldReturnDeploymentGraph()
var fileSystemDict = new Dictionary<Uri, string>();

var mainUri = DocumentUri.FromFileSystemPath("/main.bicep");
fileSystemDict[mainUri.ToUri()] = @"
fileSystemDict[mainUri.ToUriEncoded()] = @"
resource res1 'Test.Rp/basicTests@2020-01-01' = {
name: 'res1'
}
Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task RequestDeploymentGraphShouldReturnDeploymentGraph()
";

var module1Uri = DocumentUri.FromFileSystemPath("/modules/module1.bicep");
fileSystemDict[module1Uri.ToUri()] = @"
fileSystemDict[module1Uri.ToUriEncoded()] = @"
resource res3 'Test.Rp/basicTests@2020-01-01' = {
name: 'res3'
}
Expand All @@ -71,7 +71,7 @@ public async Task RequestDeploymentGraphShouldReturnDeploymentGraph()
";

var module2Uri = DocumentUri.FromFileSystemPath("/modules/module2.bicep");
fileSystemDict[module2Uri.ToUri()] = @"
fileSystemDict[module2Uri.ToUriEncoded()] = @"
resource res4 'Test.Rp/basicTests@2020-01-01' = {
name: 'res4'
}
Expand All @@ -85,7 +85,7 @@ public async Task RequestDeploymentGraphShouldReturnDeploymentGraph()
";

var nestedModuleUri = DocumentUri.FromFileSystemPath("/modules/nestedModules/nestedModule.bicep");
fileSystemDict[nestedModuleUri.ToUri()] = @"
fileSystemDict[nestedModuleUri.ToUriEncoded()] = @"
resource res5 'Test.Rp/basicTests@2020-01-01' = {
name: 'res5'
}
Expand All @@ -97,7 +97,7 @@ public async Task RequestDeploymentGraphShouldReturnDeploymentGraph()
services => services.WithNamespaceProvider(BuiltInTestTypes.Create()).WithFileResolver(new InMemoryFileResolver(fileSystemDict)));
var client = helper.Client;

client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUri()], 1));
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUriEncoded()], 1));
await diagnosticsListener.WaitNext();

var deploymentGraph = await client.SendRequest(new BicepDeploymentGraphParams(new TextDocumentIdentifier(mainUri)), default);
Expand Down
20 changes: 10 additions & 10 deletions src/Bicep.LangServer.IntegrationTests/FileWatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task Module_file_change_should_trigger_a_recompilation()
var diagsListener = new MultipleMessageListener<PublishDiagnosticsParams>();

var mainUri = DocumentUri.FromFileSystemPath("/path/to/main.bicep");
fileSystemDict[mainUri.ToUri()] = @"
fileSystemDict[mainUri.ToUriEncoded()] = @"
module myMod '../toOther/module.bicep' = {
name: 'myMod'
params: {
Expand All @@ -61,7 +61,7 @@ public async Task Module_file_change_should_trigger_a_recompilation()
";

var moduleUri = DocumentUri.FromFileSystemPath("/path/toOther/module.bicep");
fileSystemDict[moduleUri.ToUri()] = @"
fileSystemDict[moduleUri.ToUriEncoded()] = @"
// mis-spelling!
param requiredIpnut string
";
Expand All @@ -73,7 +73,7 @@ param requiredIpnut string

// open the main document
{
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUri()], 1));
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUriEncoded()], 1));

var diagsParams = await diagsListener.WaitNext();
diagsParams.Uri.Should().Be(mainUri);
Expand All @@ -82,7 +82,7 @@ param requiredIpnut string

// open the module document. this should trigger diagnostics for both the module and the main doc which references it.
{
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(moduleUri, fileSystemDict[moduleUri.ToUri()], 1));
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(moduleUri, fileSystemDict[moduleUri.ToUriEncoded()], 1));

var diagsParams = await diagsListener.WaitNext();
diagsParams.Uri.Should().Be(moduleUri);
Expand Down Expand Up @@ -129,7 +129,7 @@ public async Task Background_file_deletion_should_trigger_a_recompilation()
var diagsListener = new MultipleMessageListener<PublishDiagnosticsParams>();

var mainUri = DocumentUri.FromFileSystemPath("/path/to/main.bicep");
fileSystemDict[mainUri.ToUri()] = @"
fileSystemDict[mainUri.ToUriEncoded()] = @"
module myMod '../toOther/module.bicep' = {
name: 'myMod'
params: {
Expand All @@ -139,7 +139,7 @@ public async Task Background_file_deletion_should_trigger_a_recompilation()
";

var moduleUri = DocumentUri.FromFileSystemPath("/path/toOther/module.bicep");
fileSystemDict[moduleUri.ToUri()] = @"
fileSystemDict[moduleUri.ToUriEncoded()] = @"
// mis-spelling!
param requiredIpnut string
";
Expand All @@ -153,7 +153,7 @@ param requiredIpnut string

// open the main document
{
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUri()], 1));
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUriEncoded()], 1));

var diagsParams = await diagsListener.WaitNext();
diagsParams.Uri.Should().Be(mainUri);
Expand Down Expand Up @@ -196,7 +196,7 @@ public async Task Background_folder_deletion_should_trigger_a_recompilation()
var diagsListener = new MultipleMessageListener<PublishDiagnosticsParams>();

var mainUri = DocumentUri.FromFileSystemPath("/path/to/main.bicep");
fileSystemDict[mainUri.ToUri()] = @"
fileSystemDict[mainUri.ToUriEncoded()] = @"
module myMod '../toOther/module.bicep' = {
name: 'myMod'
params: {
Expand All @@ -206,7 +206,7 @@ public async Task Background_folder_deletion_should_trigger_a_recompilation()
";

var moduleUri = DocumentUri.FromFileSystemPath("/path/toOther/module.bicep");
fileSystemDict[moduleUri.ToUri()] = @"
fileSystemDict[moduleUri.ToUriEncoded()] = @"
// mis-spelling!
param requiredIpnut string
";
Expand All @@ -220,7 +220,7 @@ param requiredIpnut string

// open the main document
{
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUri()], 1));
client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUriEncoded()], 1));

var diagsParams = await diagsListener.WaitNext();
diagsParams.Uri.Should().Be(mainUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static async Task<LanguageServerHelper> StartServer(TestContext testConte
/// No further file opening is possible.
/// </summary>
public static Task<LanguageServerHelper> StartServerWithText(TestContext testContext, string text, DocumentUri documentUri, Action<IServiceCollection>? onRegisterServices = null)
=> StartServerWithText(testContext, new Dictionary<Uri, string> { [documentUri.ToUri()] = text }, documentUri.ToUri(), onRegisterServices);
=> StartServerWithText(testContext, new Dictionary<Uri, string> { [documentUri.ToUriEncoded()] = text }, documentUri.ToUriEncoded(), onRegisterServices);

/// <summary>
/// Starts a language client/server pair that will load the specified Bicep text and wait for the diagnostics to be published.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static DidOpenTextDocumentParams CreateDidOpenDocumentParams(DocumentUri
TextDocument = new TextDocumentItem
{
LanguageId =
PathHelper.HasBicepparamsExension(documentUri.ToUri()) ? LanguageConstants.ParamsLanguageId :
PathHelper.HasArmTemplateLikeExtension(documentUri.ToUri()) ? LanguageConstants.ArmTemplateLanguageId :
PathHelper.HasBicepparamsExension(documentUri.ToUriEncoded()) ? LanguageConstants.ParamsLanguageId :
PathHelper.HasArmTemplateLikeExtension(documentUri.ToUriEncoded()) ? LanguageConstants.ArmTemplateLanguageId :
LanguageConstants.LanguageId,
Version = version,
Uri = documentUri,
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.LangServer.IntegrationTests/HoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ public async Task Verify_Hover_ContainerRegistry(string? documentationUri, strin
string testOutputPath = FileHelper.GetUniqueTestOutputPath(TestContext);
var bicepPath = FileHelper.SaveResultFile(TestContext, "input.bicep", bicepFileContents, testOutputPath);
var documentUri = DocumentUri.FromFileSystemPath(bicepPath);
var parentModuleUri = documentUri.ToUri();
var parentModuleUri = documentUri.ToUriEncoded();

var client = await GetLanguageClientAsync(
documentUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static async Task ClassCleanup()
public async Task Overlapping_tokens_are_not_returned(DataSet dataSet)
{
var uri = DocumentUri.From($"/{dataSet.Name}");
var bicepFile = SourceFileFactory.CreateBicepFile(uri.ToUri(), dataSet.Bicep);
var bicepFile = SourceFileFactory.CreateBicepFile(uri.ToUriEncoded(), dataSet.Bicep);

var helper = await DefaultServer.GetAsync();
await helper.OpenFileOnceAsync(TestContext, dataSet.Bicep, uri);
Expand Down
Loading

0 comments on commit e0ce74d

Please sign in to comment.