Skip to content

Commit

Permalink
Merge pull request #16 from KeterSCP/allow-customizing-output-type
Browse files Browse the repository at this point in the history
Allow customizing document output type
  • Loading branch information
jogibear9988 authored Aug 21, 2023
2 parents d2ff2fa + 744f046 commit ea12062
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ public static CompletionWorkspace Create(params string[] assemblies)
return new CompletionWorkspace() { _workspace = workspace, _project = project, _metadataReferences = references };
}

public async Task<CompletionDocument> CreateDocument(string code)
public async Task<CompletionDocument> CreateDocument(string code, OutputKind outputKind = OutputKind.DynamicallyLinkedLibrary)
{
var document = _workspace.AddDocument(_project.Id, "MyFile2.cs", SourceText.From(code));
var st = await document.GetSyntaxTreeAsync();
var compilation =
CSharpCompilation
.Create("Temp",
new[] { st },
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
options: new CSharpCompilationOptions(outputKind),
references: _metadataReferences
);

Expand Down
17 changes: 17 additions & 0 deletions MonacoRoslynCompletionProvider/Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MonacoRoslynCompletionProvider;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using MonacoRoslynCompletionProvider.Api;

namespace Tests
{
Expand Down Expand Up @@ -34,5 +37,19 @@ static void Main(string[] args)
var info = await document.GetHoverInformation(258, CancellationToken.None);
var info2 = await document.GetHoverInformation(267, CancellationToken.None);
}

[TestMethod]
public async Task DocumentShouldNotContainErrorsWhenUsingTopLevelStatements()
{
const string code = @"using System;
Console.WriteLine(""Hello, world!"");
";

var ws = CompletionWorkspace.Create();
var document = await ws.CreateDocument(code, OutputKind.ConsoleApplication);
var codeCheckResults = await document.GetCodeCheckResults(CancellationToken.None);

Assert.IsTrue(codeCheckResults.All(r => r.Severity != CodeCheckSeverity.Error));
}
}
}

0 comments on commit ea12062

Please sign in to comment.