-
Notifications
You must be signed in to change notification settings - Fork 260
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
Use dafny:
Uris for standard library files
#4832
Changes from 4 commits
c4805a9
8ce5fb0
788ef9f
e38e097
88e721d
c769a16
f7004a3
72ff748
1a0d9d0
a05bc07
f12acb6
b5878f4
97bd28c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,11 +116,10 @@ public DooFile(Program dafnyProgram) { | |
private DooFile() { | ||
} | ||
|
||
public bool Validate(ErrorReporter reporter, string filePath, DafnyOptions options, Command currentCommand, | ||
IToken origin) { | ||
if (currentCommand == null) { | ||
public bool Validate(ErrorReporter reporter, string filePath, DafnyOptions options, IToken origin) { | ||
if (!options.UsingNewCli) { | ||
reporter.Error(MessageSource.Project, origin, | ||
$"Cannot load {filePath}: .doo files cannot be used with the legacy CLI"); | ||
$"cannot load {filePath}: .doo files cannot be used with the legacy CLI"); | ||
return false; | ||
} | ||
|
||
|
@@ -131,7 +130,7 @@ public bool Validate(ErrorReporter reporter, string filePath, DafnyOptions optio | |
} | ||
|
||
var success = true; | ||
var relevantOptions = currentCommand.Options.ToHashSet(); | ||
var relevantOptions = options.Options.OptionArguments.Keys.ToHashSet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still correct, given the comment immediately below? i.e. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still correct, yes |
||
foreach (var (option, check) in OptionChecks) { | ||
// It's important to only look at the options the current command uses, | ||
// because other options won't be initialized to the correct default value. | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Dafny.LanguageServer.IntegrationTest.Util; | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.Dafny.LanguageServer.IntegrationTest.Various; | ||
|
||
public class StandardLibraryTest : ClientBasedLanguageServerTest { | ||
[Fact] | ||
public async Task CanUseWrappers() { | ||
var source = @" | ||
import opened DafnyStdLibs.Wrappers | ||
|
||
const triggerSemicolonWarning := 3; | ||
|
||
method Foo() returns (s: Option<int>) { | ||
return Some(3); | ||
}".TrimStart(); | ||
|
||
var projectSource = @" | ||
[options] | ||
standard-libraries = true"; | ||
|
||
var withoutStandardLibraries = CreateAndOpenTestDocument(source); | ||
var diagnostics1 = await GetLastDiagnostics(withoutStandardLibraries, DiagnosticSeverity.Error); | ||
Assert.Single(diagnostics1); | ||
|
||
var directory = Path.GetTempFileName(); | ||
CreateAndOpenTestDocument(projectSource, Path.Combine(directory, DafnyProject.FileName)); | ||
var document = CreateAndOpenTestDocument(source, Path.Combine(directory, "document.dfy")); | ||
var diagnostics2 = await GetLastDiagnostics(document); | ||
Assert.Single(diagnostics2); | ||
Assert.Equal(DiagnosticSeverity.Warning, diagnostics2[0].Severity); | ||
} | ||
|
||
[Fact] | ||
public async Task GotoDefinition() { | ||
var source = @" | ||
import opened DafnyStdLibs.Wrappers | ||
|
||
method Foo() returns (s: ><Option<int>) { | ||
return Some(3); | ||
}".TrimStart(); | ||
|
||
var projectSource = @" | ||
[options] | ||
standard-libraries = true"; | ||
|
||
var directory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
Directory.CreateDirectory(directory); | ||
await File.WriteAllTextAsync(Path.Combine(directory, DafnyProject.FileName), projectSource); | ||
|
||
MarkupTestFile.GetPositionsAndNamedRanges(source, out var cleanSource, | ||
out var positions, out var ranges); | ||
|
||
var filePath = Path.Combine(directory, "StandardLibraryGotoDefinition.dfy"); | ||
var documentItem = CreateAndOpenTestDocument(cleanSource, filePath); | ||
await AssertNoDiagnosticsAreComing(CancellationToken); | ||
var result = await RequestDefinition(documentItem, positions[0]); | ||
Assert.Equal(new Uri("doo://dllresource.dafnypipeline/DafnyStandardLibraries.doo"), result.Single().Location.Uri); | ||
} | ||
|
||
public StandardLibraryTest(ITestOutputHelper output, LogLevel dafnyLogLevel = LogLevel.Information) : base(output, dafnyLogLevel) { | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VSCode only allows you to have custom handlers for custom schemes, which seems fair to me, but it means we have to introduce a
doo:
scheme, which is at odds with that we already handle the .doo extension as being special, even if nodoo:
scheme is used. That's why the code looks a bit funky now.If we were more strict, only allowing doo files being used as libraries, and only allowing dfy files being used as sources, then we wouldn't need to rely on the extension checking, but that seems like something to consider for the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this seems wrong enough to me to not do it at all - it really is abusing the URI scheme concept. It seems like letting VSCode understand the
dllresource:
scheme is part of the solution, but it also needs to understand that.doo
is different content format independently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a custom handler for
dllresource:
that says "if the URI ends with .doo ... else open like a normal Dafny file"? That would at least handle the standard libraries, even if we'll need to make more changes to handle doo files in general.