Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 3b50fa4

Browse files
bettinaheimricardo-espinoza
authored andcommitted
Removing temporary project (#1225)
1 parent bb96377 commit 3b50fa4

File tree

7 files changed

+36
-107
lines changed

7 files changed

+36
-107
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ ASALocalRun/
342342
src/ProjectTemplates/Quantum.App1/Quantum.App1.csproj
343343
src/ProjectTemplates/Quantum.Library1/Quantum.Library1.csproj
344344
src/ProjectTemplates/Quantum.Test1/Quantum.Test1.csproj
345-
src/QsCompiler/LanguageServer/TemporaryProject.cs
346345
src/QuantumSdk/DefaultItems/DefaultItems.props
347346
src/ProjectTemplates/Quantum.App1/.template.config/template.json
348347
src/ProjectTemplates/Quantum.Library1/.template.config/template.json

src/QsCompiler/LanguageServer/EditorState.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ internal class EditorState : IDisposable
2828

2929
private readonly Action<PublishDiagnosticParams> publish;
3030
private readonly Action<string, Dictionary<string, string?>, Dictionary<string, int>> sendTelemetry;
31-
private readonly Action<Uri>? onTemporaryProjectLoaded;
3231

3332
/// <summary>
3433
/// needed to determine if the reality of a source file that has changed on disk is indeed given by the content on disk,
@@ -60,8 +59,7 @@ internal EditorState(
6059
Action<PublishDiagnosticParams>? publishDiagnostics,
6160
Action<string, Dictionary<string, string?>, Dictionary<string, int>>? sendTelemetry,
6261
Action<string, MessageType>? log,
63-
Action<Exception>? onException,
64-
Action<Uri>? onTemporaryProjectLoaded)
62+
Action<Exception>? onException)
6563
{
6664
this.ignoreEditorUpdatesForFiles = new ConcurrentDictionary<Uri, byte>();
6765
this.sendTelemetry = sendTelemetry ?? ((eventName, properties, measurements) => { });
@@ -86,7 +84,6 @@ internal EditorState(
8684

8785
this.projectLoader = projectLoader;
8886
this.projects = new ProjectManager(onException, log, this.publish);
89-
this.onTemporaryProjectLoaded = onTemporaryProjectLoaded;
9087
}
9188

9289
/// <summary>
@@ -156,30 +153,6 @@ internal bool QsProjectLoader(Uri projectFile, [NotNullWhen(true)] out ProjectIn
156153
return true;
157154
}
158155

159-
internal Uri QsTemporaryProjectLoader(Uri sourceFileUri, string? sdkVersion)
160-
{
161-
var sourceFolderPath = Path.GetDirectoryName(sourceFileUri.LocalPath) ?? "";
162-
var projectFileName = string.Join(
163-
"_x2f_", // arbitrary string to help avoid collisions
164-
sourceFolderPath
165-
.Replace("_", "_x5f_") // arbitrary string to help avoid collisions
166-
.Split(Path.GetInvalidFileNameChars()));
167-
var projectFolderPath = Directory.CreateDirectory(Path.Combine(
168-
Path.GetTempPath(),
169-
"qsharp",
170-
projectFileName)).FullName;
171-
var projectFilePath = Path.Combine(projectFolderPath, $"generated.csproj");
172-
using (var outputFile = new StreamWriter(projectFilePath))
173-
{
174-
outputFile.WriteLine(
175-
TemporaryProject.GetFileContents(
176-
compilationScope: Path.Combine(sourceFolderPath, "*.qs"),
177-
sdkVersion: sdkVersion));
178-
}
179-
180-
return new Uri(projectFilePath);
181-
}
182-
183156
/// <summary>
184157
/// For each given uri, loads the corresponding project if the uri contains the project file for a Q# project,
185158
/// and publishes suitable diagnostics for it.

src/QsCompiler/LanguageServer/LanguageServer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ void ProcessFileEvents(IEnumerable<FileEvent> e) =>
100100
diagnostics => this.PublishDiagnosticsAsync(diagnostics),
101101
(name, props, meas) => this.SendTelemetryAsync(name, props, meas),
102102
this.LogToWindow,
103-
this.OnInternalError,
104-
this.OnTemporaryProjectLoaded);
103+
this.OnInternalError);
105104
this.waitForInit.Set();
106105
}
107106

@@ -214,9 +213,6 @@ internal void OnInternalError(Exception ex)
214213
}
215214
}
216215

217-
private void OnTemporaryProjectLoaded(Uri projectUri) =>
218-
this.fileWatcher.ListenAsync(Path.GetDirectoryName(projectUri.LocalPath), false, null, "*.csproj").Wait();
219-
220216
/* jsonrpc methods for initialization and shut down */
221217

222218
private Task InitializeWorkspaceAsync(ImmutableDictionary<Uri, ImmutableHashSet<string>> folders)

src/QsCompiler/LanguageServer/TemporaryProject.cs.v.template

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/QsCompiler/TestProjects/test14/Operation14.qs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/QsCompiler/Tests.LanguageServer/ProjectLoaderTests.cs

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ private static string ProjectFileName(string project) =>
3939
private static string SourceFileName(string project, string fileName) =>
4040
Path.Combine("TestProjects", project, fileName);
4141

42-
private (string, ProjectInformation?) Context(string project)
42+
internal static Uri ProjectUri(string project) =>
43+
new Uri(Path.GetFullPath(ProjectFileName(project)));
44+
45+
internal static (Uri, ProjectInformation?) Context(string project)
4346
{
44-
var relativePath = ProjectFileName(project);
45-
var uri = new Uri(Path.GetFullPath(relativePath));
46-
return (uri.LocalPath, CompilationContext.Load(uri));
47+
var uri = ProjectUri(project);
48+
return (uri, CompilationContext.Load(uri));
4749
}
4850

4951
[TestMethod]
@@ -75,7 +77,7 @@ public void SupportedTargetFrameworks()
7577
[TestMethod]
7678
public void FindProjectTargetFramework()
7779
{
78-
void CompareFramework(string project, string? expected)
80+
static void CompareFramework(string project, string? expected)
7981
{
8082
var projectFileName = ProjectFileName(project);
8183
var props = new ProjectLoader().DesignTimeBuildProperties(projectFileName, out var _, (x, y) => (y.Contains('.') ? 1 : 0) - (x.Contains('.') ? 1 : 0));
@@ -123,16 +125,16 @@ public void LoadNonQSharpProjects()
123125

124126
foreach (var project in invalidProjects)
125127
{
126-
var (_, context) = this.Context(project);
128+
var (_, context) = Context(project);
127129
Assert.IsNull(context);
128130
}
129131
}
130132

131133
[TestMethod]
132134
public void LoadOutdatedQSharpProject()
133135
{
134-
var (projectFile, context) = this.Context("test9");
135-
var projDir = Path.GetDirectoryName(projectFile) ?? "";
136+
var (projectFile, context) = Context("test9");
137+
var projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
136138
Assert.IsNotNull(context);
137139
Assert.AreEqual("test9.dll", Path.GetFileName(context!.Properties.OutputPath));
138140
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -151,8 +153,8 @@ public void LoadOutdatedQSharpProject()
151153
[TestMethod]
152154
public void LoadQSharpCoreLibraries()
153155
{
154-
var (projectFile, context) = this.Context("test3");
155-
var projDir = Path.GetDirectoryName(projectFile) ?? "";
156+
var (projectFile, context) = Context("test3");
157+
var projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
156158
Assert.IsNotNull(context);
157159
Assert.AreEqual("test3.dll", Path.GetFileName(context!.Properties.OutputPath));
158160
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -170,8 +172,8 @@ public void LoadQSharpCoreLibraries()
170172
Assert.IsFalse(context.UsesXunitHelper());
171173
CollectionAssert.AreEquivalent(qsFiles, context.SourceFiles.ToArray());
172174

173-
(projectFile, context) = this.Context("test12");
174-
projDir = Path.GetDirectoryName(projectFile) ?? "";
175+
(projectFile, context) = Context("test12");
176+
projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
175177
Assert.IsNotNull(context);
176178
Assert.AreEqual("test12.dll", Path.GetFileName(context!.Properties.OutputPath));
177179
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -193,8 +195,8 @@ public void LoadQSharpCoreLibraries()
193195
[TestMethod]
194196
public void LoadQSharpFrameworkLibrary()
195197
{
196-
var (projectFile, context) = this.Context("test7");
197-
var projDir = Path.GetDirectoryName(projectFile) ?? "";
198+
var (projectFile, context) = Context("test7");
199+
var projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
198200
Assert.IsNotNull(context);
199201
Assert.AreEqual("test7.dll", Path.GetFileName(context!.Properties.OutputPath));
200202
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -213,8 +215,8 @@ public void LoadQSharpFrameworkLibrary()
213215
[TestMethod]
214216
public void LoadQSharpConsoleApps()
215217
{
216-
var (projectFile, context) = this.Context("test4");
217-
var projDir = Path.GetDirectoryName(projectFile) ?? "";
218+
var (projectFile, context) = Context("test4");
219+
var projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
218220
Assert.IsNotNull(context);
219221
Assert.AreEqual("test4.dll", Path.GetFileName(context!.Properties.OutputPath));
220222
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -230,8 +232,8 @@ public void LoadQSharpConsoleApps()
230232
Assert.IsTrue(context.UsesProject("test3.csproj"));
231233
CollectionAssert.AreEquivalent(qsFiles, context.SourceFiles.ToArray());
232234

233-
(projectFile, context) = this.Context("test10");
234-
projDir = Path.GetDirectoryName(projectFile) ?? "";
235+
(projectFile, context) = Context("test10");
236+
projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
235237
Assert.IsNotNull(context);
236238
Assert.AreEqual("test10.dll", Path.GetFileName(context!.Properties.OutputPath));
237239
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -245,8 +247,8 @@ public void LoadQSharpConsoleApps()
245247
Assert.IsTrue(context.UsesCanon());
246248
CollectionAssert.AreEquivalent(qsFiles, context.SourceFiles.ToArray());
247249

248-
(projectFile, context) = this.Context("test11");
249-
projDir = Path.GetDirectoryName(projectFile) ?? "";
250+
(projectFile, context) = Context("test11");
251+
projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
250252
Assert.IsNotNull(context);
251253
Assert.AreEqual("test11.dll", Path.GetFileName(context!.Properties.OutputPath));
252254
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -264,8 +266,8 @@ public void LoadQSharpConsoleApps()
264266
[TestMethod]
265267
public void LoadQSharpUnitTest()
266268
{
267-
var (projectFile, context) = this.Context("test5");
268-
var projDir = Path.GetDirectoryName(projectFile) ?? "";
269+
var (projectFile, context) = Context("test5");
270+
var projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
269271
Assert.IsNotNull(context);
270272
Assert.AreEqual("test5.dll", Path.GetFileName(context!.Properties.OutputPath));
271273
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -288,8 +290,8 @@ public void LoadQSharpUnitTest()
288290
[TestMethod]
289291
public void LoadQSharpMultiFrameworkLibrary()
290292
{
291-
var (projectFile, context) = this.Context("test6");
292-
var projDir = Path.GetDirectoryName(projectFile) ?? "";
293+
var (projectFile, context) = Context("test6");
294+
var projDir = Path.GetDirectoryName(projectFile.LocalPath) ?? "";
293295
Assert.IsNotNull(context);
294296
Assert.AreEqual("test6.dll", Path.GetFileName(context!.Properties.OutputPath));
295297
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));
@@ -307,34 +309,18 @@ public void LoadQSharpMultiFrameworkLibrary()
307309
Assert.IsTrue(context.UsesProject("test3.csproj"));
308310
CollectionAssert.AreEquivalent(qsFiles, context.SourceFiles.ToArray());
309311
}
310-
311-
[TestMethod]
312-
public void LoadQSharpTemporaryProject()
313-
{
314-
var sourceFile = Path.GetFullPath(SourceFileName("test14", "Operation14.qs"));
315-
var projectUri = CompilationContext.CreateTemporaryProject(new Uri(sourceFile), "0.12.20072031");
316-
Assert.IsNotNull(projectUri);
317-
318-
var qsFiles = new string[] { sourceFile };
319-
var projectInformation = CompilationContext.Load(projectUri);
320-
Assert.IsNotNull(projectInformation);
321-
Assert.IsTrue(projectInformation!.UsesCanon());
322-
CollectionAssert.AreEquivalent(qsFiles, projectInformation!.SourceFiles.ToArray());
323-
}
324312
}
325313

326314
internal static class CompilationContext
327315
{
328316
private static void LogOutput(string msg, MessageType level) =>
329317
Console.WriteLine($"[{level}]: {msg}");
330318

331-
internal static ProjectInformation? Load(Uri projectFile) =>
332-
new EditorState(new ProjectLoader(LogOutput), null, null, null, null, null)
333-
.QsProjectLoader(projectFile, out var loaded) ? loaded : null;
319+
internal static EditorState Editor =>
320+
new EditorState(new ProjectLoader(LogOutput), null, null, null, null);
334321

335-
internal static Uri CreateTemporaryProject(Uri sourceFile, string sdkVersion) =>
336-
new EditorState(new ProjectLoader(LogOutput), null, null, null, null, null)
337-
.QsTemporaryProjectLoader(sourceFile, sdkVersion);
322+
internal static ProjectInformation? Load(Uri projectFile) =>
323+
Editor.QsProjectLoader(projectFile, out var loaded) ? loaded : null;
338324

339325
internal static bool UsesDll(this ProjectInformation info, string dll) => info.References.Any(r => r.EndsWith(dll));
340326

@@ -343,6 +329,8 @@ internal static Uri CreateTemporaryProject(Uri sourceFile, string sdkVersion) =>
343329
// NB: We check whether the project uses either the 0.3–0.5 name (Primitives) or the 0.6– name (Intrinsic).
344330
internal static bool UsesIntrinsics(this ProjectInformation info) => info.UsesDll("Microsoft.Quantum.Intrinsic.dll") || info.UsesDll("Microsoft.Quantum.Primitives.dll");
345331

332+
internal static bool UsesQSharpCore(this ProjectInformation info) => info.UsesDll("Microsoft.Quantum.QSharp.Core.dll");
333+
346334
internal static bool UsesCanon(this ProjectInformation info) =>
347335
info.UsesDll("Microsoft.Quantum.Canon.dll") ||
348336
info.UsesDll("Microsoft.Quantum.Standard.dll");

src/QsCompiler/Tests.LanguageServer/Tests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ async Task RunTest(bool emptyLastLine, bool useQsExtension)
274274
}
275275
}
276276

277+
await RunTest(emptyLastLine: true, useQsExtension: true);
277278
await RunTest(emptyLastLine: true, useQsExtension: false);
279+
await RunTest(emptyLastLine: false, useQsExtension: true);
278280
await RunTest(emptyLastLine: false, useQsExtension: false);
279-
await RunTest(emptyLastLine: true, useQsExtension: true);
280281
}
281282

282283
[TestMethod]

0 commit comments

Comments
 (0)