microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
logo

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/npm/qsharp/test/languageService.js

83lines · modeblame

4439ba19Mine Starks1 years ago1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// @ts-check
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { log } from "../dist/log.js";
9import { getLanguageService } from "../dist/main.js";
10
11log.setLogLevel("warn");
12
13// Minimal IProjectHost implementation for testing
14const dummyHost = {
15readFile: async () => null,
16listDirectory: async () => [],
17resolvePath: async (a, b) => b,
18fetchGithub: async () => "",
19findManifestDirectory: async () => null,
20};
21
22test("devDiagnostics configuration works", async () => {
23const languageService = getLanguageService(dummyHost);
24
25try {
26// Collect diagnostics events as they are raised
27const diagnosticEvents = [];
28languageService.addEventListener("diagnostics", (event) => {
29diagnosticEvents.push({
30uri: event.detail.uri,
31diagnostics: event.detail.diagnostics.map((diag) => ({
32code: diag.code,
33})),
34});
35});
36
37// Enable dev diagnostics
38await languageService.updateConfiguration({
39devDiagnostics: true,
40});
41
42// Update a document
43await languageService.updateDocument(
44"test.qs",
451,
46"namespace Test { @EntryPoint() operation Main() : Unit {} }",
47"qsharp",
48);
49
50await new Promise((resolve) => setTimeout(resolve, 0));
51
52// Should have received diagnostic events
53assert.deepEqual(diagnosticEvents, [
54{
55diagnostics: [
56{
57code: "Qdk.Dev.DocumentStatus",
58},
59],
60uri: "test.qs",
61},
62]);
63
64// Test disabling dev diagnostics
65diagnosticEvents.length = 0;
66
67await languageService.updateConfiguration({
68devDiagnostics: false,
69});
70
71await new Promise((resolve) => setTimeout(resolve, 0));
72
73// Diagnostics should be cleared
74assert.deepEqual(diagnosticEvents, [
75{
76diagnostics: [],
77uri: "test.qs",
78},
79]);
80} finally {
81await languageService.dispose();
82}
83});