qsharp-lang 1.0.13-dev → 1.0.17-rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/language-service/language-service.d.ts +7 -3
- package/dist/language-service/language-service.js +39 -0
- package/dist/language-service/worker-proxy.js +2 -0
- package/dist/samples.generated.js +1 -1
- package/dist/vsdiagnostic.d.ts +2 -10
- package/dist/vsdiagnostic.js +9 -0
- package/lib/node/qsc_wasm.cjs +45 -21
- package/lib/node/qsc_wasm.d.cts +79 -57
- package/lib/node/qsc_wasm_bg.wasm +0 -0
- package/lib/web/qsc_wasm.d.ts +92 -68
- package/lib/web/qsc_wasm.js +44 -20
- package/lib/web/qsc_wasm_bg.wasm +0 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ICompletionList, IHover, IDefinition, ISignatureHelp, IWorkspaceConfiguration, IWorkspaceEdit, ITextEdit } from "../../lib/node/qsc_wasm.cjs";
|
|
2
2
|
import { VSDiagnostic } from "../vsdiagnostic.js";
|
|
3
3
|
import { IServiceProxy } from "../worker-proxy.js";
|
|
4
4
|
type QscWasm = typeof import("../../lib/node/qsc_wasm.cjs");
|
|
@@ -17,8 +17,10 @@ export interface ILanguageService {
|
|
|
17
17
|
getCompletions(documentUri: string, offset: number): Promise<ICompletionList>;
|
|
18
18
|
getHover(documentUri: string, offset: number): Promise<IHover | undefined>;
|
|
19
19
|
getDefinition(documentUri: string, offset: number): Promise<IDefinition | undefined>;
|
|
20
|
-
dispose(): Promise<void>;
|
|
21
20
|
getSignatureHelp(documentUri: string, offset: number): Promise<ISignatureHelp | undefined>;
|
|
21
|
+
getRename(documentUri: string, offset: number, newName: string): Promise<IWorkspaceEdit | undefined>;
|
|
22
|
+
prepareRename(documentUri: string, offset: number): Promise<ITextEdit | undefined>;
|
|
23
|
+
dispose(): Promise<void>;
|
|
22
24
|
addEventListener<T extends LanguageServiceEvent["type"]>(type: T, listener: (event: Extract<LanguageServiceEvent, {
|
|
23
25
|
type: T;
|
|
24
26
|
}>) => void): void;
|
|
@@ -40,6 +42,8 @@ export declare class QSharpLanguageService implements ILanguageService {
|
|
|
40
42
|
getHover(documentUri: string, offset: number): Promise<IHover | undefined>;
|
|
41
43
|
getDefinition(documentUri: string, offset: number): Promise<IDefinition | undefined>;
|
|
42
44
|
getSignatureHelp(documentUri: string, offset: number): Promise<ISignatureHelp | undefined>;
|
|
45
|
+
getRename(documentUri: string, offset: number, newName: string): Promise<IWorkspaceEdit | undefined>;
|
|
46
|
+
prepareRename(documentUri: string, offset: number): Promise<ITextEdit | undefined>;
|
|
43
47
|
dispose(): Promise<void>;
|
|
44
48
|
addEventListener<T extends LanguageServiceEvent["type"]>(type: T, listener: (event: Extract<LanguageServiceEvent, {
|
|
45
49
|
type: T;
|
|
@@ -47,6 +51,6 @@ export declare class QSharpLanguageService implements ILanguageService {
|
|
|
47
51
|
removeEventListener<T extends LanguageServiceEvent["type"]>(type: T, listener: (event: Extract<LanguageServiceEvent, {
|
|
48
52
|
type: T;
|
|
49
53
|
}>) => void): void;
|
|
50
|
-
onDiagnostics(uri: string, version: number, diagnostics:
|
|
54
|
+
onDiagnostics(uri: string, version: number, diagnostics: VSDiagnostic[]): void;
|
|
51
55
|
}
|
|
52
56
|
export {};
|
|
@@ -98,6 +98,45 @@ export class QSharpLanguageService {
|
|
|
98
98
|
}
|
|
99
99
|
return result;
|
|
100
100
|
}
|
|
101
|
+
async getRename(documentUri, offset, newName) {
|
|
102
|
+
const code = this.code[documentUri];
|
|
103
|
+
if (code === undefined) {
|
|
104
|
+
log.error(`expected ${documentUri} to be in the document map`);
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
const convertedOffset = mapUtf16UnitsToUtf8Units([offset], code)[offset];
|
|
108
|
+
const result = this.languageService.get_rename(documentUri, convertedOffset, newName);
|
|
109
|
+
const mappedChanges = [];
|
|
110
|
+
for (const [uri, edits] of result.changes) {
|
|
111
|
+
const code = this.code[uri];
|
|
112
|
+
if (code) {
|
|
113
|
+
const mappedEdits = edits.map((edit) => {
|
|
114
|
+
const mappedSpan = mapUtf8UnitsToUtf16Units([edit.range.start, edit.range.end], code);
|
|
115
|
+
edit.range.start = mappedSpan[edit.range.start];
|
|
116
|
+
edit.range.end = mappedSpan[edit.range.end];
|
|
117
|
+
return edit;
|
|
118
|
+
});
|
|
119
|
+
mappedChanges.push([uri, mappedEdits]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
result.changes = mappedChanges;
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
async prepareRename(documentUri, offset) {
|
|
126
|
+
const code = this.code[documentUri];
|
|
127
|
+
if (code === undefined) {
|
|
128
|
+
log.error(`expected ${documentUri} to be in the document map`);
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
const convertedOffset = mapUtf16UnitsToUtf8Units([offset], code)[offset];
|
|
132
|
+
const result = this.languageService.prepare_rename(documentUri, convertedOffset);
|
|
133
|
+
if (result) {
|
|
134
|
+
const mappedSpan = mapUtf8UnitsToUtf16Units([result.range.start, result.range.end], code);
|
|
135
|
+
result.range.start = mappedSpan[result.range.start];
|
|
136
|
+
result.range.end = mappedSpan[result.range.end];
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
101
140
|
async dispose() {
|
|
102
141
|
this.languageService.free();
|
|
103
142
|
}
|
|
@@ -9,6 +9,8 @@ const requests = {
|
|
|
9
9
|
getHover: "request",
|
|
10
10
|
getDefinition: "request",
|
|
11
11
|
getSignatureHelp: "request",
|
|
12
|
+
getRename: "request",
|
|
13
|
+
prepareRename: "request",
|
|
12
14
|
dispose: "request",
|
|
13
15
|
addEventListener: "addEventListener",
|
|
14
16
|
removeEventListener: "removeEventListener",
|
|
@@ -57,6 +57,6 @@ export default [
|
|
|
57
57
|
{
|
|
58
58
|
"title": "Shor",
|
|
59
59
|
"shots": 1,
|
|
60
|
-
"code": "/// # Sample\n/// Shor's algorithm\n///\n/// # Description\n/// Shor's algorithm is a quantum algorithm for finding the prime factors of an\n/// integer.\n///\n/// This Q# program implements Shor's algorithm.\nnamespace Sample {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Random;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arithmetic;\n open Microsoft.Quantum.Arrays;\n\n @EntryPoint()\n operation Main() : (Int, Int) {\n let n = 143; // 11*13;\n // You can try these other examples for a lengthier computation.\n // let n = 16837; // = 113*149\n // let n = 22499; // = 149*151\n\n // Use Shor's algorithm to factor a semiprime integer.\n let (a, b) = FactorSemiprimeInteger(n);\n Message($\"Found factorization {n} = {a} * {b} \");\n return (a, b);\n }\n\n /// # Summary\n /// Uses Shor's algorithm to factor an input number.\n ///\n /// # Input\n /// ## number\n /// A semiprime integer to be factored.\n ///\n /// # Output\n /// Pair of numbers p > 1 and q > 1 such that p⋅q = `number`\n operation FactorSemiprimeInteger(number : Int) : (Int, Int) {\n // First check the most trivial case (the provided number is even).\n if number % 2 == 0 {\n Message(\"An even number has been given; 2 is a factor.\");\n return (number / 2, 2);\n }\n // These mutables will keep track of whether we found the factors, and\n // if so, what they are. The default value for the factors is (1,1).\n mutable foundFactors = false;\n mutable factors = (1, 1);\n mutable attempt = 1;\n repeat {\n Message($\"*** Factorizing {number}, attempt {attempt}.\");\n // Try to guess a number co-prime to `number` by getting a random\n // integer in the interval [1, number-1]\n let generator = DrawRandomInt(1, number - 1);\n\n // Check if the random integer is indeed co-prime.\n // If true use Quantum algorithm for Period finding.\n if GreatestCommonDivisorI(generator, number) == 1 {\n Message($\"Estimating period of {generator}.\");\n\n // Call Quantum Period finding algorithm for\n // `generator` mod `number`.\n let period = EstimatePeriod(generator, number);\n\n // Set the flag and factors values if the continued\n // fractions classical algorithm succeeds.\n set (foundFactors, factors) =\n MaybeFactorsFromPeriod(number, generator, period);\n }\n // In this case, we guessed a divisor by accident.\n else {\n // Find divisor.\n let gcd = GreatestCommonDivisorI(number, generator);\n Message($\"We have guessed a divisor {gcd} by accident. \" +\n \"No quantum computation was done.\");\n\n // Set the flag `foundFactors` to true, indicating that we\n // succeeded in finding factors.\n set foundFactors = true;\n set factors = (gcd, number / gcd);\n }\n set attempt = attempt+1;\n if (attempt > 100) {\n fail \"Failed to find factors: too many attempts!\";\n }\n }\n until foundFactors\n fixup {\n Message(\"The estimated period did not yield a valid factor. \" +\n \"Trying again.\");\n }\n\n // Return the factorization\n return factors;\n }\n\n /// # Summary\n /// Tries to find the factors of `modulus` given a `period` and `generator`.\n ///\n /// # Input\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## period\n /// The estimated period (multiplicative order) of the generator mod\n /// `modulus`.\n ///\n /// # Output\n /// A tuple of a flag indicating whether factors were found successfully,\n /// and a pair of integers representing the factors that were found.\n /// Note that the second output is only meaningful when the first output is\n /// `true`.\n function MaybeFactorsFromPeriod(\n modulus : Int,\n generator : Int,\n period : Int)\n : (Bool, (Int, Int)) {\n\n // Period finding reduces to factoring only if period is even\n if period % 2 == 0 {\n // Compute `generator` ^ `period/2` mod `number`.\n let halfPower = ExpModI(generator, period / 2, modulus);\n\n // If we are unlucky, halfPower is just -1 mod N, which is a trivial\n // case and not useful for factoring.\n if halfPower != modulus - 1 {\n // When the halfPower is not -1 mod N, halfPower-1 or\n // halfPower+1 share non-trivial divisor with `number`. Find it.\n let factor = MaxI(\n GreatestCommonDivisorI(halfPower - 1, modulus),\n GreatestCommonDivisorI(halfPower + 1, modulus)\n );\n\n // Add a flag that we found the factors, and return computed\n // non-trivial factors.\n Message($\"Found factor={factor}\");\n return (true, (factor, modulus / factor));\n } else {\n // Return a flag indicating we hit a trivial case and didn't get\n // any factors.\n Message($\"Found trivial factors.\");\n return (false, (1, 1));\n }\n } else {\n // When period is odd we have to pick another generator to estimate\n // period of and start over.\n Message($\"Estimated period {period} was odd, trying again.\");\n return (false, (1, 1));\n }\n }\n\n /// # Summary\n /// Find the period of a number from an input frequency.\n ///\n /// # Input\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## frequencyEstimate\n /// The frequency that we want to convert to a period.\n /// ## bitsPrecision\n /// Number of bits of precision with which we need to estimate s/r to\n /// recover period r using continued fractions algorithm.\n /// ## currentDivisor\n /// The divisor of the generator period found so far.\n ///\n /// # Output\n /// The period as calculated from the estimated frequency via the continued\n /// fractions algorithm.\n function PeriodFromFrequency(\n modulus : Int,\n frequencyEstimate : Int,\n bitsPrecision : Int,\n currentDivisor : Int)\n : Int {\n // Now we use the ContinuedFractionConvergentI function to recover s/r\n // from dyadic fraction k/2^bitsPrecision.\n let (numerator, period) = ContinuedFractionConvergentI(\n (frequencyEstimate, 2 ^ bitsPrecision),\n modulus);\n\n // ContinuedFractionConvergentI does not guarantee the signs of the\n // numerator and denominator. Here we make sure that both are positive\n // using AbsI.\n let (numeratorAbs, periodAbs) = (AbsI(numerator), AbsI(period));\n\n // Compute and return the newly found divisor.\n let period =\n (periodAbs * currentDivisor) /\n GreatestCommonDivisorI(currentDivisor, periodAbs);\n Message($\"Found period={period}\");\n return period;\n }\n\n /// # Summary\n /// Finds a multiplicative order of the generator in the residue ring Z mod\n /// `modulus`.\n ///\n /// # Input\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n ///\n /// # Output\n /// The period (multiplicative order) of the generator mod `modulus`\n operation EstimatePeriod(generator : Int, modulus : Int) : Int {\n // Here we check that the inputs to the EstimatePeriod operation are\n // valid.\n Fact(\n GreatestCommonDivisorI(generator, modulus) == 1,\n \"`generator` and `modulus` must be co-prime\");\n\n // Number of bits in the modulus with respect to which we are estimating\n // the period.\n let bitsize = BitSizeI(modulus);\n\n // The EstimatePeriod operation estimates the period r by finding an\n // approximation k/2^(bits precision) to a fraction s/r, where s is some\n // integer. Note that if s and r have common divisors we will end up\n // recovering a divisor of r and not r itself.\n\n // Number of bits of precision with which we need to estimate s/r to\n // recover period r, using continued fractions algorithm.\n let bitsPrecision = 2 * bitsize + 1;\n\n // Current estimate for the frequency of the form s/r.\n let frequencyEstimate = EstimateFrequency(generator, modulus, bitsize);\n if frequencyEstimate != 0 {\n return PeriodFromFrequency(\n modulus, frequencyEstimate, bitsPrecision, 1);\n }\n else {\n Message(\"The estimated frequency was 0, trying again.\");\n return 1;\n }\n }\n\n /// # Summary\n /// Estimates the frequency of a generator in the residue ring Z mod\n /// `modulus`.\n ///\n /// # Input\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## bitsize\n /// Number of bits needed to represent the modulus.\n ///\n /// # Output\n /// The numerator k of dyadic fraction k/2^bitsPrecision approximating s/r.\n operation EstimateFrequency(generator : Int,modulus : Int, bitsize : Int)\n : Int {\n mutable frequencyEstimate = 0;\n let bitsPrecision = 2 * bitsize + 1;\n Message($\"Estimating frequency with bitsPrecision={bitsPrecision}.\");\n\n // Allocate qubits for the superposition of eigenstates of the oracle\n // that is used in period finding.\n use eigenstateRegister = Qubit[bitsize];\n\n // Initialize eigenstateRegister to 1, which is a superposition of the\n // eigenstates we are estimating the phases of.\n // We are interpreting the register as encoding an unsigned integer in\n // little-endian format.\n ApplyXorInPlace(1, eigenstateRegister);\n\n // Use phase estimation with a semiclassical Fourier transform to\n // estimate the frequency.\n use c = Qubit();\n for idx in bitsPrecision-1..-1..0 {\n H(c);\n Controlled ApplyOrderFindingOracle(\n [c],\n (generator, modulus, 1 <<< idx, eigenstateRegister));\n R1Frac(frequencyEstimate, bitsPrecision-1-idx, c);\n H(c);\n if M(c) == One {\n X(c); // Reset\n set frequencyEstimate += 1 <<< (bitsPrecision-1-idx);\n }\n }\n\n // Return all the qubits used for oracle's eigenstate back to 0 state\n // using ResetAll.\n ResetAll(eigenstateRegister);\n Message($\"Estimated frequency={frequencyEstimate}\");\n return frequencyEstimate;\n }\n\n /// # Summary\n /// Interprets `target` as encoding unsigned little-endian integer k and\n /// performs transformation |k⟩ ↦ |gᵖ⋅k mod N ⟩ where p is `power`, g is\n /// `generator` and N is `modulus`.\n ///\n /// # Input\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## power\n /// Power of `generator` by which `target` is multiplied.\n /// ## target\n /// Register interpreted as little-endian which is multiplied by given power\n /// of the generator. The multiplication is performed modulo `modulus`.\n operation ApplyOrderFindingOracle(\n generator : Int,\n modulus : Int,\n power : Int,\n target : Qubit[])\n : Unit is Adj + Ctl {\n // Check that the parameters satisfy the requirements.\n Fact(\n GreatestCommonDivisorI(generator, modulus) == 1,\n \"`generator` and `modulus` must be co-prime\");\n\n // The oracle we use for order finding implements |x⟩ ↦ |x⋅a mod N⟩.\n // We also use `ExpModI` to compute a by which x must be multiplied.\n // Also note that we interpret target as unsigned integer in\n // little-endian fromat.\n ModularMultiplyByConstant(\n modulus,\n ExpModI(generator, power, modulus),\n target);\n }\n\n //\n // Arithmetic helper functions to implement order-finding oracle.\n //\n\n /// # Summary\n /// Returns the number of trailing zeroes of a number.\n ///\n /// ## Example\n /// let zeroes = NTrailingZeroes(21); // NTrailingZeroes(0b1101) = 0\n /// let zeroes = NTrailingZeroes(20); // NTrailingZeroes(0b1100) = 2\n function NTrailingZeroes(number : Int) : Int {\n Fact(number != 0, \"NTrailingZeroes: number cannot be 0.\");\n mutable nZeroes = 0;\n mutable copy = number;\n while (copy % 2 == 0) {\n set nZeroes += 1;\n set copy /= 2;\n }\n return nZeroes;\n }\n\n /// # Summary\n /// Performs modular in-place multiplication by a classical constant.\n ///\n /// # Description\n /// Given the classical constants `c` and `modulus`, and an input quantum\n /// register |𝑦⟩ in little-endian format, this operation computes\n /// `(c*x) % modulus` into |𝑦⟩.\n ///\n /// # Input\n /// ## modulus\n /// Modulus to use for modular multiplication\n /// ## c\n /// Constant by which to multiply |𝑦⟩\n /// ## y\n /// Quantum register of target\n operation ModularMultiplyByConstant(modulus : Int, c : Int, y : Qubit[])\n : Unit is Adj + Ctl {\n use qs = Qubit[Length(y)];\n for idx in IndexRange(y) {\n let shiftedC = (c <<< idx) % modulus;\n Controlled ModularAddConstant(\n [y[idx]],\n (modulus, shiftedC, qs));\n }\n for idx in IndexRange(y) {\n SWAP(y[idx], qs[idx]);\n }\n let invC = InverseModI(c, modulus);\n for idx in IndexRange(y) {\n let shiftedC = (invC <<< idx) % modulus;\n Controlled ModularAddConstant(\n [y[idx]],\n (modulus, modulus - shiftedC, qs));\n }\n }\n\n /// # Summary\n /// Performs modular in-place addition of a classical constant into a\n /// quantum register.\n ///\n /// # Description\n /// Given the classical constants `c` and `modulus`, and an input quantum\n /// register |𝑦⟩ in little-endian format, this operation computes\n /// `(x+c) % modulus` into |𝑦⟩.\n ///\n /// # Input\n /// ## modulus\n /// Modulus to use for modular addition\n /// ## c\n /// Constant to add to |𝑦⟩\n /// ## y\n /// Quantum register of target\n operation ModularAddConstant(modulus : Int, c : Int, y : Qubit[])\n : Unit is Adj + Ctl {\n body (...) {\n Controlled ModularAddConstant([], (modulus, c, y));\n }\n controlled (ctrls, ...) {\n // We apply a custom strategy to control this operation instead of\n // letting the compiler create the controlled variant for us in\n // which the `Controlled` functor would be distributed over each\n // operation in the body.\n //\n // Here we can use some scratch memory to save ensure that at most\n // one control qubit is used for costly operations such as\n // `AddConstant` and `CompareGreaterThenOrEqualConstant`.\n if Length(ctrls) >= 2 {\n use control = Qubit();\n within {\n Controlled X(ctrls, control);\n } apply {\n Controlled ModularAddConstant(\n [control],\n (modulus, c, y));\n }\n } else {\n use carry = Qubit();\n Controlled AddConstant(\n ctrls, (c, y + [carry]));\n Controlled Adjoint AddConstant(\n ctrls, (modulus, y + [carry]));\n Controlled AddConstant(\n [carry], (modulus, y));\n Controlled CompareGreaterThanOrEqualConstant(\n ctrls, (c, y, carry));\n }\n }\n }\n\n /// # Summary\n /// Performs in-place addition of a constant into a quantum register.\n ///\n /// # Description\n /// Given a non-empty quantum register |𝑦⟩ of length 𝑛+1 and a positive\n // constant 𝑐 < 2ⁿ, computes |𝑦 + c⟩ into |𝑦⟩.\n ///\n /// # Input\n /// ## c\n /// Constant number to add to |𝑦⟩.\n /// ## y\n /// Quantum register of second summand and target; must not be empty.\n operation AddConstant(c : Int, y : Qubit[]) : Unit is Adj + Ctl {\n // We are using this version instead of the library version that is\n // based on Fourier angles to show an advantage of sparse simulation\n // in this sample.\n let n = Length(y);\n Fact(n > 0, \"Bit width must be at least 1\");\n Fact(c >= 0, \"constant must not be negative\");\n Fact(c < 2^n, \"constant must be smaller than {2^n)}\");\n if c != 0 {\n // If c has j trailing zeroes than the j least significant bits of y\n // won't be affected by the addition and can therefore be ignored by\n // applying the addition only to the other qubits and shifting c\n // accordingly.\n let j = NTrailingZeroes(c);\n use x = Qubit[n - j];\n within {\n ApplyXorInPlace(c >>> j, x);\n } apply {\n AddI(x, y[j...]);\n }\n }\n }\n\n /// # Summary\n /// Performs greater-than-or-equals comparison to a constant.\n ///\n /// # Description\n /// Toggles output qubit `target` if and only if input register `x` is\n /// greater than or equal to `c`.\n ///\n /// # Input\n /// ## c\n /// Constant value for comparison.\n /// ## x\n /// Quantum register to compare against.\n /// ## target\n /// Target qubit for comparison result.\n ///\n /// # Reference\n /// This construction is described in [Lemma 3, arXiv:2201.10200]\n operation CompareGreaterThanOrEqualConstant(\n c : Int,\n x : Qubit[],\n target : Qubit)\n : Unit is Adj+Ctl {\n let bitWidth = Length(x);\n if c == 0 {\n X(target);\n } elif c >= (2^bitWidth) {\n // do nothing\n } elif c == (2^(bitWidth - 1)) {\n CNOT(Tail(x), target);\n } else {\n // normalize constant\n let l = NTrailingZeroes(c);\n let cNormalized = c >>> l;\n let xNormalized = x[l...];\n let bitWidthNormalized = Length(xNormalized);\n use qs = Qubit[bitWidthNormalized - 1];\n let cs1 = [Head(xNormalized)] + Most(qs);\n Fact(Length(cs1) == Length(qs),\n \"Arrays should be of the same length.\");\n within {\n for i in 0..Length(cs1)-1 {\n let op =\n cNormalized &&& (1 <<< (i+1)) != 0 ?\n ApplyAnd | ApplyOr;\n op(cs1[i], xNormalized[i+1], qs[i]);\n }\n } apply {\n CNOT(Tail(qs), target);\n }\n }\n }\n\n /// # Summary\n /// Inverts a given target qubit if and only if both control qubits are in\n /// the 1 state, using measurement to perform the adjoint operation.\n ///\n /// # Description\n /// Inverts `target` if and only if both controls are 1, but assumes that\n /// `target` is in state 0. The operation has T-count 4, T-depth 2 and\n /// requires no helper qubit, and may therefore be preferable to a CCNOT\n /// operation, if `target` is known to be 0.\n /// The adjoint of this operation is measurement based and requires no T\n /// gates.\n /// Although the Toffoli gate (CCNOT) will perform faster in in simulations,\n /// this version has lower T gate requirements.\n ///\n /// # Input\n /// ## control1\n /// First control qubit\n /// ## control2\n /// Second control qubit\n /// ## target\n /// Target auxiliary qubit; must be in state 0\n ///\n /// # References\n /// - Cody Jones: \"Novel constructions for the fault-tolerant\n /// Toffoli gate\",\n /// Phys. Rev. A 87, 022328, 2013\n /// [arXiv:1212.5069](https://arxiv.org/abs/1212.5069)\n /// doi:10.1103/PhysRevA.87.022328\n /// - Craig Gidney: \"Halving the cost of quantum addition\",\n /// Quantum 2, page 74, 2018\n /// [arXiv:1709.06648](https://arxiv.org/abs/1709.06648)\n /// doi:10.1103/PhysRevA.85.044302\n /// - Mathias Soeken: \"Quantum Oracle Circuits and the Christmas\n /// Tree Pattern\",\n /// [Blog article from December 19, 2019](https://msoeken.github.io/blog_qac.html)\n /// (note: explains the multiple controlled construction)\n operation ApplyAnd(control1 : Qubit, control2 : Qubit, target : Qubit)\n : Unit is Adj {\n body (...) {\n H(target);\n T(target);\n CNOT(control1, target);\n CNOT(control2, target);\n within {\n CNOT(target, control1);\n CNOT(target, control2);\n }\n apply {\n Adjoint T(control1);\n Adjoint T(control2);\n T(target);\n }\n H(target);\n S(target);\n }\n adjoint (...) {\n H(target);\n if (M(target) == One) {\n X(target);\n CZ(control1, control2);\n }\n }\n }\n\n /// # Summary\n /// Applies X to the target if any of the controls are 1.\n operation ApplyOr(control1 : Qubit, control2 : Qubit, target : Qubit)\n : Unit is Adj {\n within {\n ApplyToEachA(X, [control1, control2]);\n } apply {\n ApplyAnd(control1, control2, target);\n X(target);\n }\n }\n}\n"
|
|
60
|
+
"code": "/// # Sample\n/// Shor's algorithm\n///\n/// # Description\n/// Shor's algorithm is a quantum algorithm for finding the prime factors of an\n/// integer.\n///\n/// This Q# program implements Shor's algorithm.\nnamespace Sample {\n open Microsoft.Quantum.Diagnostics;\n open Microsoft.Quantum.Random;\n open Microsoft.Quantum.Math;\n open Microsoft.Quantum.Arithmetic;\n open Microsoft.Quantum.Arrays;\n\n @EntryPoint()\n operation Main() : (Int, Int) {\n let n = 143; // 11*13;\n // You can try these other examples for a lengthier computation.\n // let n = 16837; // = 113*149\n // let n = 22499; // = 149*151\n\n // Use Shor's algorithm to factor a semiprime integer.\n let (a, b) = FactorSemiprimeInteger(n);\n Message($\"Found factorization {n} = {a} * {b} \");\n return (a, b);\n }\n\n /// # Summary\n /// Uses Shor's algorithm to factor an input number.\n ///\n /// # Input\n /// ## number\n /// A semiprime integer to be factored.\n ///\n /// # Output\n /// Pair of numbers p > 1 and q > 1 such that p⋅q = `number`\n operation FactorSemiprimeInteger(number : Int) : (Int, Int) {\n // First check the most trivial case (the provided number is even).\n if number % 2 == 0 {\n Message(\"An even number has been given; 2 is a factor.\");\n return (number / 2, 2);\n }\n // These mutables will keep track of whether we found the factors, and\n // if so, what they are. The default value for the factors is (1,1).\n mutable foundFactors = false;\n mutable factors = (1, 1);\n mutable attempt = 1;\n repeat {\n Message($\"*** Factorizing {number}, attempt {attempt}.\");\n // Try to guess a number co-prime to `number` by getting a random\n // integer in the interval [1, number-1]\n let generator = DrawRandomInt(1, number - 1);\n\n // Check if the random integer is indeed co-prime.\n // If true use Quantum algorithm for Period finding.\n if GreatestCommonDivisorI(generator, number) == 1 {\n Message($\"Estimating period of {generator}.\");\n\n // Call Quantum Period finding algorithm for\n // `generator` mod `number`.\n let period = EstimatePeriod(generator, number);\n\n // Set the flag and factors values if the continued\n // fractions classical algorithm succeeds.\n set (foundFactors, factors) =\n MaybeFactorsFromPeriod(number, generator, period);\n }\n // In this case, we guessed a divisor by accident.\n else {\n // Find divisor.\n let gcd = GreatestCommonDivisorI(number, generator);\n Message($\"We have guessed a divisor {gcd} by accident. \" +\n \"No quantum computation was done.\");\n\n // Set the flag `foundFactors` to true, indicating that we\n // succeeded in finding factors.\n set foundFactors = true;\n set factors = (gcd, number / gcd);\n }\n set attempt = attempt+1;\n if (attempt > 100) {\n fail \"Failed to find factors: too many attempts!\";\n }\n }\n until foundFactors\n fixup {\n Message(\"The estimated period did not yield a valid factor. \" +\n \"Trying again.\");\n }\n\n // Return the factorization\n return factors;\n }\n\n /// # Summary\n /// Tries to find the factors of `modulus` given a `period` and `generator`.\n ///\n /// # Input\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## period\n /// The estimated period (multiplicative order) of the generator mod\n /// `modulus`.\n ///\n /// # Output\n /// A tuple of a flag indicating whether factors were found successfully,\n /// and a pair of integers representing the factors that were found.\n /// Note that the second output is only meaningful when the first output is\n /// `true`.\n function MaybeFactorsFromPeriod(\n modulus : Int,\n generator : Int,\n period : Int)\n : (Bool, (Int, Int)) {\n\n // Period finding reduces to factoring only if period is even\n if period % 2 == 0 {\n // Compute `generator` ^ `period/2` mod `number`.\n let halfPower = ExpModI(generator, period / 2, modulus);\n\n // If we are unlucky, halfPower is just -1 mod N, which is a trivial\n // case and not useful for factoring.\n if halfPower != modulus - 1 {\n // When the halfPower is not -1 mod N, halfPower-1 or\n // halfPower+1 share non-trivial divisor with `number`. Find it.\n let factor = MaxI(\n GreatestCommonDivisorI(halfPower - 1, modulus),\n GreatestCommonDivisorI(halfPower + 1, modulus)\n );\n\n // Add a flag that we found the factors, and return only if computed\n // non-trivial factors (not like 1:n or n:1)\n if (factor != 1) and (factor != modulus) {\n Message($\"Found factor={factor}\");\n return (true, (factor, modulus / factor));\n }\n } \n // Return a flag indicating we hit a trivial case and didn't get\n // any factors.\n Message($\"Found trivial factors.\");\n return (false, (1, 1));\n } else {\n // When period is odd we have to pick another generator to estimate\n // period of and start over.\n Message($\"Estimated period {period} was odd, trying again.\");\n return (false, (1, 1));\n }\n }\n\n /// # Summary\n /// Find the period of a number from an input frequency.\n ///\n /// # Input\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## frequencyEstimate\n /// The frequency that we want to convert to a period.\n /// ## bitsPrecision\n /// Number of bits of precision with which we need to estimate s/r to\n /// recover period r using continued fractions algorithm.\n /// ## currentDivisor\n /// The divisor of the generator period found so far.\n ///\n /// # Output\n /// The period as calculated from the estimated frequency via the continued\n /// fractions algorithm.\n function PeriodFromFrequency(\n modulus : Int,\n frequencyEstimate : Int,\n bitsPrecision : Int,\n currentDivisor : Int)\n : Int {\n // Now we use the ContinuedFractionConvergentI function to recover s/r\n // from dyadic fraction k/2^bitsPrecision.\n let (numerator, period) = ContinuedFractionConvergentI(\n (frequencyEstimate, 2 ^ bitsPrecision),\n modulus);\n\n // ContinuedFractionConvergentI does not guarantee the signs of the\n // numerator and denominator. Here we make sure that both are positive\n // using AbsI.\n let (numeratorAbs, periodAbs) = (AbsI(numerator), AbsI(period));\n\n // Compute and return the newly found divisor.\n let period =\n (periodAbs * currentDivisor) /\n GreatestCommonDivisorI(currentDivisor, periodAbs);\n Message($\"Found period={period}\");\n return period;\n }\n\n /// # Summary\n /// Finds a multiplicative order of the generator in the residue ring Z mod\n /// `modulus`.\n ///\n /// # Input\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n ///\n /// # Output\n /// The period (multiplicative order) of the generator mod `modulus`\n operation EstimatePeriod(generator : Int, modulus : Int) : Int {\n // Here we check that the inputs to the EstimatePeriod operation are\n // valid.\n Fact(\n GreatestCommonDivisorI(generator, modulus) == 1,\n \"`generator` and `modulus` must be co-prime\");\n\n // Number of bits in the modulus with respect to which we are estimating\n // the period.\n let bitsize = BitSizeI(modulus);\n\n // The EstimatePeriod operation estimates the period r by finding an\n // approximation k/2^(bits precision) to a fraction s/r, where s is some\n // integer. Note that if s and r have common divisors we will end up\n // recovering a divisor of r and not r itself.\n\n // Number of bits of precision with which we need to estimate s/r to\n // recover period r, using continued fractions algorithm.\n let bitsPrecision = 2 * bitsize + 1;\n\n // Current estimate for the frequency of the form s/r.\n let frequencyEstimate = EstimateFrequency(generator, modulus, bitsize);\n if frequencyEstimate != 0 {\n return PeriodFromFrequency(\n modulus, frequencyEstimate, bitsPrecision, 1);\n }\n else {\n Message(\"The estimated frequency was 0, trying again.\");\n return 1;\n }\n }\n\n /// # Summary\n /// Estimates the frequency of a generator in the residue ring Z mod\n /// `modulus`.\n ///\n /// # Input\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## bitsize\n /// Number of bits needed to represent the modulus.\n ///\n /// # Output\n /// The numerator k of dyadic fraction k/2^bitsPrecision approximating s/r.\n operation EstimateFrequency(generator : Int,modulus : Int, bitsize : Int)\n : Int {\n mutable frequencyEstimate = 0;\n let bitsPrecision = 2 * bitsize + 1;\n Message($\"Estimating frequency with bitsPrecision={bitsPrecision}.\");\n\n // Allocate qubits for the superposition of eigenstates of the oracle\n // that is used in period finding.\n use eigenstateRegister = Qubit[bitsize];\n\n // Initialize eigenstateRegister to 1, which is a superposition of the\n // eigenstates we are estimating the phases of.\n // We are interpreting the register as encoding an unsigned integer in\n // little-endian format.\n ApplyXorInPlace(1, eigenstateRegister);\n\n // Use phase estimation with a semiclassical Fourier transform to\n // estimate the frequency.\n use c = Qubit();\n for idx in bitsPrecision-1..-1..0 {\n H(c);\n Controlled ApplyOrderFindingOracle(\n [c],\n (generator, modulus, 1 <<< idx, eigenstateRegister));\n R1Frac(frequencyEstimate, bitsPrecision-1-idx, c);\n H(c);\n if M(c) == One {\n X(c); // Reset\n set frequencyEstimate += 1 <<< (bitsPrecision-1-idx);\n }\n }\n\n // Return all the qubits used for oracle's eigenstate back to 0 state\n // using ResetAll.\n ResetAll(eigenstateRegister);\n Message($\"Estimated frequency={frequencyEstimate}\");\n return frequencyEstimate;\n }\n\n /// # Summary\n /// Interprets `target` as encoding unsigned little-endian integer k and\n /// performs transformation |k⟩ ↦ |gᵖ⋅k mod N ⟩ where p is `power`, g is\n /// `generator` and N is `modulus`.\n ///\n /// # Input\n /// ## generator\n /// The unsigned integer multiplicative order (period) of which is being\n /// estimated. Must be co-prime to `modulus`.\n /// ## modulus\n /// The modulus which defines the residue ring Z mod `modulus` in which the\n /// multiplicative order of `generator` is being estimated.\n /// ## power\n /// Power of `generator` by which `target` is multiplied.\n /// ## target\n /// Register interpreted as little-endian which is multiplied by given power\n /// of the generator. The multiplication is performed modulo `modulus`.\n operation ApplyOrderFindingOracle(\n generator : Int,\n modulus : Int,\n power : Int,\n target : Qubit[])\n : Unit is Adj + Ctl {\n // Check that the parameters satisfy the requirements.\n Fact(\n GreatestCommonDivisorI(generator, modulus) == 1,\n \"`generator` and `modulus` must be co-prime\");\n\n // The oracle we use for order finding implements |x⟩ ↦ |x⋅a mod N⟩.\n // We also use `ExpModI` to compute a by which x must be multiplied.\n // Also note that we interpret target as unsigned integer in\n // little-endian fromat.\n ModularMultiplyByConstant(\n modulus,\n ExpModI(generator, power, modulus),\n target);\n }\n\n //\n // Arithmetic helper functions to implement order-finding oracle.\n //\n\n /// # Summary\n /// Returns the number of trailing zeroes of a number.\n ///\n /// ## Example\n /// let zeroes = NTrailingZeroes(21); // NTrailingZeroes(0b1101) = 0\n /// let zeroes = NTrailingZeroes(20); // NTrailingZeroes(0b1100) = 2\n function NTrailingZeroes(number : Int) : Int {\n Fact(number != 0, \"NTrailingZeroes: number cannot be 0.\");\n mutable nZeroes = 0;\n mutable copy = number;\n while (copy % 2 == 0) {\n set nZeroes += 1;\n set copy /= 2;\n }\n return nZeroes;\n }\n\n /// # Summary\n /// Performs modular in-place multiplication by a classical constant.\n ///\n /// # Description\n /// Given the classical constants `c` and `modulus`, and an input quantum\n /// register |𝑦⟩ in little-endian format, this operation computes\n /// `(c*x) % modulus` into |𝑦⟩.\n ///\n /// # Input\n /// ## modulus\n /// Modulus to use for modular multiplication\n /// ## c\n /// Constant by which to multiply |𝑦⟩\n /// ## y\n /// Quantum register of target\n operation ModularMultiplyByConstant(modulus : Int, c : Int, y : Qubit[])\n : Unit is Adj + Ctl {\n use qs = Qubit[Length(y)];\n for idx in IndexRange(y) {\n let shiftedC = (c <<< idx) % modulus;\n Controlled ModularAddConstant(\n [y[idx]],\n (modulus, shiftedC, qs));\n }\n for idx in IndexRange(y) {\n SWAP(y[idx], qs[idx]);\n }\n let invC = InverseModI(c, modulus);\n for idx in IndexRange(y) {\n let shiftedC = (invC <<< idx) % modulus;\n Controlled ModularAddConstant(\n [y[idx]],\n (modulus, modulus - shiftedC, qs));\n }\n }\n\n /// # Summary\n /// Performs modular in-place addition of a classical constant into a\n /// quantum register.\n ///\n /// # Description\n /// Given the classical constants `c` and `modulus`, and an input quantum\n /// register |𝑦⟩ in little-endian format, this operation computes\n /// `(x+c) % modulus` into |𝑦⟩.\n ///\n /// # Input\n /// ## modulus\n /// Modulus to use for modular addition\n /// ## c\n /// Constant to add to |𝑦⟩\n /// ## y\n /// Quantum register of target\n operation ModularAddConstant(modulus : Int, c : Int, y : Qubit[])\n : Unit is Adj + Ctl {\n body (...) {\n Controlled ModularAddConstant([], (modulus, c, y));\n }\n controlled (ctrls, ...) {\n // We apply a custom strategy to control this operation instead of\n // letting the compiler create the controlled variant for us in\n // which the `Controlled` functor would be distributed over each\n // operation in the body.\n //\n // Here we can use some scratch memory to save ensure that at most\n // one control qubit is used for costly operations such as\n // `AddConstant` and `CompareGreaterThenOrEqualConstant`.\n if Length(ctrls) >= 2 {\n use control = Qubit();\n within {\n Controlled X(ctrls, control);\n } apply {\n Controlled ModularAddConstant(\n [control],\n (modulus, c, y));\n }\n } else {\n use carry = Qubit();\n Controlled AddConstant(\n ctrls, (c, y + [carry]));\n Controlled Adjoint AddConstant(\n ctrls, (modulus, y + [carry]));\n Controlled AddConstant(\n [carry], (modulus, y));\n Controlled CompareGreaterThanOrEqualConstant(\n ctrls, (c, y, carry));\n }\n }\n }\n\n /// # Summary\n /// Performs in-place addition of a constant into a quantum register.\n ///\n /// # Description\n /// Given a non-empty quantum register |𝑦⟩ of length 𝑛+1 and a positive\n // constant 𝑐 < 2ⁿ, computes |𝑦 + c⟩ into |𝑦⟩.\n ///\n /// # Input\n /// ## c\n /// Constant number to add to |𝑦⟩.\n /// ## y\n /// Quantum register of second summand and target; must not be empty.\n operation AddConstant(c : Int, y : Qubit[]) : Unit is Adj + Ctl {\n // We are using this version instead of the library version that is\n // based on Fourier angles to show an advantage of sparse simulation\n // in this sample.\n let n = Length(y);\n Fact(n > 0, \"Bit width must be at least 1\");\n Fact(c >= 0, \"constant must not be negative\");\n Fact(c < 2^n, \"constant must be smaller than {2^n)}\");\n if c != 0 {\n // If c has j trailing zeroes than the j least significant bits of y\n // won't be affected by the addition and can therefore be ignored by\n // applying the addition only to the other qubits and shifting c\n // accordingly.\n let j = NTrailingZeroes(c);\n use x = Qubit[n - j];\n within {\n ApplyXorInPlace(c >>> j, x);\n } apply {\n AddI(x, y[j...]);\n }\n }\n }\n\n /// # Summary\n /// Performs greater-than-or-equals comparison to a constant.\n ///\n /// # Description\n /// Toggles output qubit `target` if and only if input register `x` is\n /// greater than or equal to `c`.\n ///\n /// # Input\n /// ## c\n /// Constant value for comparison.\n /// ## x\n /// Quantum register to compare against.\n /// ## target\n /// Target qubit for comparison result.\n ///\n /// # Reference\n /// This construction is described in [Lemma 3, arXiv:2201.10200]\n operation CompareGreaterThanOrEqualConstant(\n c : Int,\n x : Qubit[],\n target : Qubit)\n : Unit is Adj+Ctl {\n let bitWidth = Length(x);\n if c == 0 {\n X(target);\n } elif c >= (2^bitWidth) {\n // do nothing\n } elif c == (2^(bitWidth - 1)) {\n CNOT(Tail(x), target);\n } else {\n // normalize constant\n let l = NTrailingZeroes(c);\n let cNormalized = c >>> l;\n let xNormalized = x[l...];\n let bitWidthNormalized = Length(xNormalized);\n use qs = Qubit[bitWidthNormalized - 1];\n let cs1 = [Head(xNormalized)] + Most(qs);\n Fact(Length(cs1) == Length(qs),\n \"Arrays should be of the same length.\");\n within {\n for i in 0..Length(cs1)-1 {\n let op =\n cNormalized &&& (1 <<< (i+1)) != 0 ?\n ApplyAnd | ApplyOr;\n op(cs1[i], xNormalized[i+1], qs[i]);\n }\n } apply {\n CNOT(Tail(qs), target);\n }\n }\n }\n\n /// # Summary\n /// Inverts a given target qubit if and only if both control qubits are in\n /// the 1 state, using measurement to perform the adjoint operation.\n ///\n /// # Description\n /// Inverts `target` if and only if both controls are 1, but assumes that\n /// `target` is in state 0. The operation has T-count 4, T-depth 2 and\n /// requires no helper qubit, and may therefore be preferable to a CCNOT\n /// operation, if `target` is known to be 0.\n /// The adjoint of this operation is measurement based and requires no T\n /// gates.\n /// Although the Toffoli gate (CCNOT) will perform faster in in simulations,\n /// this version has lower T gate requirements.\n ///\n /// # Input\n /// ## control1\n /// First control qubit\n /// ## control2\n /// Second control qubit\n /// ## target\n /// Target auxiliary qubit; must be in state 0\n ///\n /// # References\n /// - Cody Jones: \"Novel constructions for the fault-tolerant\n /// Toffoli gate\",\n /// Phys. Rev. A 87, 022328, 2013\n /// [arXiv:1212.5069](https://arxiv.org/abs/1212.5069)\n /// doi:10.1103/PhysRevA.87.022328\n /// - Craig Gidney: \"Halving the cost of quantum addition\",\n /// Quantum 2, page 74, 2018\n /// [arXiv:1709.06648](https://arxiv.org/abs/1709.06648)\n /// doi:10.1103/PhysRevA.85.044302\n /// - Mathias Soeken: \"Quantum Oracle Circuits and the Christmas\n /// Tree Pattern\",\n /// [Blog article from December 19, 2019](https://msoeken.github.io/blog_qac.html)\n /// (note: explains the multiple controlled construction)\n operation ApplyAnd(control1 : Qubit, control2 : Qubit, target : Qubit)\n : Unit is Adj {\n body (...) {\n H(target);\n T(target);\n CNOT(control1, target);\n CNOT(control2, target);\n within {\n CNOT(target, control1);\n CNOT(target, control2);\n }\n apply {\n Adjoint T(control1);\n Adjoint T(control2);\n T(target);\n }\n H(target);\n S(target);\n }\n adjoint (...) {\n H(target);\n if (M(target) == One) {\n X(target);\n CZ(control1, control2);\n }\n }\n }\n\n /// # Summary\n /// Applies X to the target if any of the controls are 1.\n operation ApplyOr(control1 : Qubit, control2 : Qubit, target : Qubit)\n : Unit is Adj {\n within {\n ApplyToEachA(X, [control1, control2]);\n } apply {\n ApplyAnd(control1, control2, target);\n X(target);\n }\n }\n}\n"
|
|
61
61
|
}
|
|
62
62
|
];
|
package/dist/vsdiagnostic.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
end_pos: number;
|
|
4
|
-
message: string;
|
|
5
|
-
severity: "error" | "warning" | "info";
|
|
6
|
-
code?: {
|
|
7
|
-
value: string;
|
|
8
|
-
target: string;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
1
|
+
import { type VSDiagnostic } from "../lib/web/qsc_wasm.js";
|
|
2
|
+
export { type VSDiagnostic } from "../lib/web/qsc_wasm.js";
|
|
11
3
|
/**
|
|
12
4
|
* @param positions - An array of utf-8 code unit indexes to map to utf-16 code unit indexes
|
|
13
5
|
* @param source - The source code to do the mapping on
|
package/dist/vsdiagnostic.js
CHANGED
|
@@ -104,6 +104,10 @@ export function mapDiagnostics(diags, code) {
|
|
|
104
104
|
diags.forEach((diag) => {
|
|
105
105
|
positions.push(diag.start_pos);
|
|
106
106
|
positions.push(diag.end_pos);
|
|
107
|
+
diag.related?.forEach((related) => {
|
|
108
|
+
positions.push(related.start_pos);
|
|
109
|
+
positions.push(related.end_pos);
|
|
110
|
+
});
|
|
107
111
|
});
|
|
108
112
|
const positionMap = mapUtf8UnitsToUtf16Units(positions, code);
|
|
109
113
|
// Return the diagnostics with the positions mapped (or EOF if couldn't resolve)
|
|
@@ -112,6 +116,11 @@ export function mapDiagnostics(diags, code) {
|
|
|
112
116
|
// The mapped position may well be 0, so need to use ?? rather than ||
|
|
113
117
|
start_pos: positionMap[diag.start_pos] ?? code.length,
|
|
114
118
|
end_pos: positionMap[diag.end_pos] ?? code.length,
|
|
119
|
+
related: diag.related?.map((related) => ({
|
|
120
|
+
...related,
|
|
121
|
+
start_pos: positionMap[related.start_pos] ?? code.length,
|
|
122
|
+
end_pos: positionMap[related.end_pos] ?? code.length,
|
|
123
|
+
})),
|
|
115
124
|
}));
|
|
116
125
|
return results;
|
|
117
126
|
}
|
package/lib/node/qsc_wasm.cjs
CHANGED
|
@@ -327,6 +327,21 @@ module.exports.check_exercise_solution = function(solution_code, exercise_source
|
|
|
327
327
|
}
|
|
328
328
|
};
|
|
329
329
|
|
|
330
|
+
let cachedUint32Memory0 = null;
|
|
331
|
+
|
|
332
|
+
function getUint32Memory0() {
|
|
333
|
+
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
|
|
334
|
+
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
335
|
+
}
|
|
336
|
+
return cachedUint32Memory0;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
340
|
+
const ptr = malloc(arg.length * 4);
|
|
341
|
+
getUint32Memory0().set(arg, ptr / 4);
|
|
342
|
+
WASM_VECTOR_LEN = arg.length;
|
|
343
|
+
return ptr;
|
|
344
|
+
}
|
|
330
345
|
/**
|
|
331
346
|
* @param {any} callback
|
|
332
347
|
* @param {number} level
|
|
@@ -352,22 +367,6 @@ module.exports.setLogLevel = function(level) {
|
|
|
352
367
|
wasm.setLogLevel(level);
|
|
353
368
|
};
|
|
354
369
|
|
|
355
|
-
let cachedUint32Memory0 = null;
|
|
356
|
-
|
|
357
|
-
function getUint32Memory0() {
|
|
358
|
-
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
|
|
359
|
-
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
360
|
-
}
|
|
361
|
-
return cachedUint32Memory0;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function passArray32ToWasm0(arg, malloc) {
|
|
365
|
-
const ptr = malloc(arg.length * 4);
|
|
366
|
-
getUint32Memory0().set(arg, ptr / 4);
|
|
367
|
-
WASM_VECTOR_LEN = arg.length;
|
|
368
|
-
return ptr;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
370
|
function handleError(f, args) {
|
|
372
371
|
try {
|
|
373
372
|
return f.apply(this, args);
|
|
@@ -662,6 +661,31 @@ class LanguageService {
|
|
|
662
661
|
const ret = wasm.languageservice_get_signature_help(this.ptr, ptr0, len0, offset);
|
|
663
662
|
return takeObject(ret);
|
|
664
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* @param {string} uri
|
|
666
|
+
* @param {number} offset
|
|
667
|
+
* @param {string} new_name
|
|
668
|
+
* @returns {IWorkspaceEdit}
|
|
669
|
+
*/
|
|
670
|
+
get_rename(uri, offset, new_name) {
|
|
671
|
+
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
672
|
+
const len0 = WASM_VECTOR_LEN;
|
|
673
|
+
const ptr1 = passStringToWasm0(new_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
674
|
+
const len1 = WASM_VECTOR_LEN;
|
|
675
|
+
const ret = wasm.languageservice_get_rename(this.ptr, ptr0, len0, offset, ptr1, len1);
|
|
676
|
+
return takeObject(ret);
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* @param {string} uri
|
|
680
|
+
* @param {number} offset
|
|
681
|
+
* @returns {ITextEdit | undefined}
|
|
682
|
+
*/
|
|
683
|
+
prepare_rename(uri, offset) {
|
|
684
|
+
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
685
|
+
const len0 = WASM_VECTOR_LEN;
|
|
686
|
+
const ret = wasm.languageservice_prepare_rename(this.ptr, ptr0, len0, offset);
|
|
687
|
+
return takeObject(ret);
|
|
688
|
+
}
|
|
665
689
|
}
|
|
666
690
|
module.exports.LanguageService = LanguageService;
|
|
667
691
|
|
|
@@ -719,6 +743,11 @@ module.exports.__wbindgen_object_clone_ref = function(arg0) {
|
|
|
719
743
|
return addHeapObject(ret);
|
|
720
744
|
};
|
|
721
745
|
|
|
746
|
+
module.exports.__wbindgen_number_new = function(arg0) {
|
|
747
|
+
const ret = arg0;
|
|
748
|
+
return addHeapObject(ret);
|
|
749
|
+
};
|
|
750
|
+
|
|
722
751
|
module.exports.__wbg_new_0232637a3cb0b1a7 = function() {
|
|
723
752
|
const ret = new Error();
|
|
724
753
|
return addHeapObject(ret);
|
|
@@ -732,11 +761,6 @@ module.exports.__wbg_stack_3090cd8fd3702c6e = function(arg0, arg1) {
|
|
|
732
761
|
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
733
762
|
};
|
|
734
763
|
|
|
735
|
-
module.exports.__wbindgen_number_new = function(arg0) {
|
|
736
|
-
const ret = arg0;
|
|
737
|
-
return addHeapObject(ret);
|
|
738
|
-
};
|
|
739
|
-
|
|
740
764
|
module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
|
|
741
765
|
const ret = getObject(arg0) == getObject(arg1);
|
|
742
766
|
return ret;
|
package/lib/node/qsc_wasm.d.cts
CHANGED
|
@@ -52,69 +52,20 @@ export enum StepResultId {
|
|
|
52
52
|
StepOut = 3,
|
|
53
53
|
Return = 4,
|
|
54
54
|
}
|
|
55
|
-
export interface
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface ICompletionItem {
|
|
65
|
-
label: string;
|
|
66
|
-
kind: "function" | "interface" | "keyword" | "module";
|
|
67
|
-
sortText?: string;
|
|
68
|
-
detail?: string;
|
|
69
|
-
additionalTextEdits?: ITextEdit[];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface ITextEdit {
|
|
73
|
-
range: ISpan;
|
|
74
|
-
newText: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface IHover {
|
|
78
|
-
contents: string;
|
|
79
|
-
span: ISpan
|
|
55
|
+
export interface VSDiagnostic {
|
|
56
|
+
start_pos: number;
|
|
57
|
+
end_pos: number;
|
|
58
|
+
message: string;
|
|
59
|
+
severity: "error" | "warning" | "info"
|
|
60
|
+
code?: string;
|
|
61
|
+
related?: IRelatedInformation[];
|
|
80
62
|
}
|
|
81
63
|
|
|
82
|
-
export interface
|
|
64
|
+
export interface IRelatedInformation {
|
|
83
65
|
source: string;
|
|
84
|
-
offset: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface ISignatureHelp {
|
|
88
|
-
signatures: ISignatureInformation[];
|
|
89
|
-
activeSignature: number;
|
|
90
|
-
activeParameter: number;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface ISignatureInformation {
|
|
94
|
-
label: string;
|
|
95
|
-
documentation?: string;
|
|
96
|
-
parameters: IParameterInformation[];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface IParameterInformation {
|
|
100
|
-
label: ISpan;
|
|
101
|
-
documentation?: string;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface ISpan {
|
|
105
|
-
start: number;
|
|
106
|
-
end: number;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface IDiagnostic {
|
|
110
66
|
start_pos: number;
|
|
111
67
|
end_pos: number;
|
|
112
68
|
message: string;
|
|
113
|
-
severity: "error" | "warning" | "info"
|
|
114
|
-
code?: {
|
|
115
|
-
value: string;
|
|
116
|
-
target: string;
|
|
117
|
-
}
|
|
118
69
|
}
|
|
119
70
|
|
|
120
71
|
export interface IStructStepResult {
|
|
@@ -176,6 +127,64 @@ export interface IQuantumState {
|
|
|
176
127
|
value: string;
|
|
177
128
|
}
|
|
178
129
|
|
|
130
|
+
export interface IWorkspaceConfiguration {
|
|
131
|
+
targetProfile?: "full" | "base";
|
|
132
|
+
packageType?: "exe" | "lib";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ICompletionList {
|
|
136
|
+
items: ICompletionItem[]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface ICompletionItem {
|
|
140
|
+
label: string;
|
|
141
|
+
kind: "function" | "interface" | "keyword" | "module" | "property";
|
|
142
|
+
sortText?: string;
|
|
143
|
+
detail?: string;
|
|
144
|
+
additionalTextEdits?: ITextEdit[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface ITextEdit {
|
|
148
|
+
range: ISpan;
|
|
149
|
+
newText: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface IHover {
|
|
153
|
+
contents: string;
|
|
154
|
+
span: ISpan
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface IDefinition {
|
|
158
|
+
source: string;
|
|
159
|
+
offset: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface ISignatureHelp {
|
|
163
|
+
signatures: ISignatureInformation[];
|
|
164
|
+
activeSignature: number;
|
|
165
|
+
activeParameter: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface ISignatureInformation {
|
|
169
|
+
label: string;
|
|
170
|
+
documentation?: string;
|
|
171
|
+
parameters: IParameterInformation[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface IParameterInformation {
|
|
175
|
+
label: ISpan;
|
|
176
|
+
documentation?: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface IWorkspaceEdit {
|
|
180
|
+
changes: [string, ITextEdit[]][];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface ISpan {
|
|
184
|
+
start: number;
|
|
185
|
+
end: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
179
188
|
/**
|
|
180
189
|
*/
|
|
181
190
|
export class DebugService {
|
|
@@ -278,4 +287,17 @@ export class LanguageService {
|
|
|
278
287
|
* @returns {ISignatureHelp | undefined}
|
|
279
288
|
*/
|
|
280
289
|
get_signature_help(uri: string, offset: number): ISignatureHelp | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* @param {string} uri
|
|
292
|
+
* @param {number} offset
|
|
293
|
+
* @param {string} new_name
|
|
294
|
+
* @returns {IWorkspaceEdit}
|
|
295
|
+
*/
|
|
296
|
+
get_rename(uri: string, offset: number, new_name: string): IWorkspaceEdit;
|
|
297
|
+
/**
|
|
298
|
+
* @param {string} uri
|
|
299
|
+
* @param {number} offset
|
|
300
|
+
* @returns {ITextEdit | undefined}
|
|
301
|
+
*/
|
|
302
|
+
prepare_rename(uri: string, offset: number): ITextEdit | undefined;
|
|
281
303
|
}
|
|
Binary file
|
package/lib/web/qsc_wasm.d.ts
CHANGED
|
@@ -52,69 +52,20 @@ export enum StepResultId {
|
|
|
52
52
|
StepOut = 3,
|
|
53
53
|
Return = 4,
|
|
54
54
|
}
|
|
55
|
-
export interface
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface ICompletionItem {
|
|
65
|
-
label: string;
|
|
66
|
-
kind: "function" | "interface" | "keyword" | "module";
|
|
67
|
-
sortText?: string;
|
|
68
|
-
detail?: string;
|
|
69
|
-
additionalTextEdits?: ITextEdit[];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface ITextEdit {
|
|
73
|
-
range: ISpan;
|
|
74
|
-
newText: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface IHover {
|
|
78
|
-
contents: string;
|
|
79
|
-
span: ISpan
|
|
55
|
+
export interface VSDiagnostic {
|
|
56
|
+
start_pos: number;
|
|
57
|
+
end_pos: number;
|
|
58
|
+
message: string;
|
|
59
|
+
severity: "error" | "warning" | "info"
|
|
60
|
+
code?: string;
|
|
61
|
+
related?: IRelatedInformation[];
|
|
80
62
|
}
|
|
81
63
|
|
|
82
|
-
export interface
|
|
64
|
+
export interface IRelatedInformation {
|
|
83
65
|
source: string;
|
|
84
|
-
offset: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface ISignatureHelp {
|
|
88
|
-
signatures: ISignatureInformation[];
|
|
89
|
-
activeSignature: number;
|
|
90
|
-
activeParameter: number;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface ISignatureInformation {
|
|
94
|
-
label: string;
|
|
95
|
-
documentation?: string;
|
|
96
|
-
parameters: IParameterInformation[];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface IParameterInformation {
|
|
100
|
-
label: ISpan;
|
|
101
|
-
documentation?: string;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface ISpan {
|
|
105
|
-
start: number;
|
|
106
|
-
end: number;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface IDiagnostic {
|
|
110
66
|
start_pos: number;
|
|
111
67
|
end_pos: number;
|
|
112
68
|
message: string;
|
|
113
|
-
severity: "error" | "warning" | "info"
|
|
114
|
-
code?: {
|
|
115
|
-
value: string;
|
|
116
|
-
target: string;
|
|
117
|
-
}
|
|
118
69
|
}
|
|
119
70
|
|
|
120
71
|
export interface IStructStepResult {
|
|
@@ -176,6 +127,64 @@ export interface IQuantumState {
|
|
|
176
127
|
value: string;
|
|
177
128
|
}
|
|
178
129
|
|
|
130
|
+
export interface IWorkspaceConfiguration {
|
|
131
|
+
targetProfile?: "full" | "base";
|
|
132
|
+
packageType?: "exe" | "lib";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ICompletionList {
|
|
136
|
+
items: ICompletionItem[]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface ICompletionItem {
|
|
140
|
+
label: string;
|
|
141
|
+
kind: "function" | "interface" | "keyword" | "module" | "property";
|
|
142
|
+
sortText?: string;
|
|
143
|
+
detail?: string;
|
|
144
|
+
additionalTextEdits?: ITextEdit[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface ITextEdit {
|
|
148
|
+
range: ISpan;
|
|
149
|
+
newText: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface IHover {
|
|
153
|
+
contents: string;
|
|
154
|
+
span: ISpan
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface IDefinition {
|
|
158
|
+
source: string;
|
|
159
|
+
offset: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface ISignatureHelp {
|
|
163
|
+
signatures: ISignatureInformation[];
|
|
164
|
+
activeSignature: number;
|
|
165
|
+
activeParameter: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface ISignatureInformation {
|
|
169
|
+
label: string;
|
|
170
|
+
documentation?: string;
|
|
171
|
+
parameters: IParameterInformation[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface IParameterInformation {
|
|
175
|
+
label: ISpan;
|
|
176
|
+
documentation?: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface IWorkspaceEdit {
|
|
180
|
+
changes: [string, ITextEdit[]][];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface ISpan {
|
|
184
|
+
start: number;
|
|
185
|
+
end: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
179
188
|
/**
|
|
180
189
|
*/
|
|
181
190
|
export class DebugService {
|
|
@@ -278,6 +287,19 @@ export class LanguageService {
|
|
|
278
287
|
* @returns {ISignatureHelp | undefined}
|
|
279
288
|
*/
|
|
280
289
|
get_signature_help(uri: string, offset: number): ISignatureHelp | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* @param {string} uri
|
|
292
|
+
* @param {number} offset
|
|
293
|
+
* @param {string} new_name
|
|
294
|
+
* @returns {IWorkspaceEdit}
|
|
295
|
+
*/
|
|
296
|
+
get_rename(uri: string, offset: number, new_name: string): IWorkspaceEdit;
|
|
297
|
+
/**
|
|
298
|
+
* @param {string} uri
|
|
299
|
+
* @param {number} offset
|
|
300
|
+
* @returns {ITextEdit | undefined}
|
|
301
|
+
*/
|
|
302
|
+
prepare_rename(uri: string, offset: number): ITextEdit | undefined;
|
|
281
303
|
}
|
|
282
304
|
|
|
283
305
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
@@ -290,17 +312,6 @@ export interface InitOutput {
|
|
|
290
312
|
readonly get_hir: (a: number, b: number, c: number) => void;
|
|
291
313
|
readonly run: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
292
314
|
readonly check_exercise_solution: (a: number, b: number, c: number, d: number) => number;
|
|
293
|
-
readonly __wbg_languageservice_free: (a: number) => void;
|
|
294
|
-
readonly languageservice_new: (a: number) => number;
|
|
295
|
-
readonly languageservice_update_configuration: (a: number, b: number) => void;
|
|
296
|
-
readonly languageservice_update_document: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
297
|
-
readonly languageservice_close_document: (a: number, b: number, c: number) => void;
|
|
298
|
-
readonly languageservice_get_completions: (a: number, b: number, c: number, d: number) => number;
|
|
299
|
-
readonly languageservice_get_definition: (a: number, b: number, c: number, d: number) => number;
|
|
300
|
-
readonly languageservice_get_hover: (a: number, b: number, c: number, d: number) => number;
|
|
301
|
-
readonly languageservice_get_signature_help: (a: number, b: number, c: number, d: number) => number;
|
|
302
|
-
readonly initLogging: (a: number, b: number, c: number) => void;
|
|
303
|
-
readonly setLogLevel: (a: number) => void;
|
|
304
315
|
readonly __wbg_debugservice_free: (a: number) => void;
|
|
305
316
|
readonly debugservice_new: () => number;
|
|
306
317
|
readonly debugservice_load_source: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
@@ -312,6 +323,19 @@ export interface InitOutput {
|
|
|
312
323
|
readonly debugservice_eval_step_out: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
313
324
|
readonly debugservice_get_breakpoints: (a: number, b: number, c: number) => number;
|
|
314
325
|
readonly debugservice_get_locals: (a: number) => number;
|
|
326
|
+
readonly __wbg_languageservice_free: (a: number) => void;
|
|
327
|
+
readonly languageservice_new: (a: number) => number;
|
|
328
|
+
readonly languageservice_update_configuration: (a: number, b: number) => void;
|
|
329
|
+
readonly languageservice_update_document: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
330
|
+
readonly languageservice_close_document: (a: number, b: number, c: number) => void;
|
|
331
|
+
readonly languageservice_get_completions: (a: number, b: number, c: number, d: number) => number;
|
|
332
|
+
readonly languageservice_get_definition: (a: number, b: number, c: number, d: number) => number;
|
|
333
|
+
readonly languageservice_get_hover: (a: number, b: number, c: number, d: number) => number;
|
|
334
|
+
readonly languageservice_get_signature_help: (a: number, b: number, c: number, d: number) => number;
|
|
335
|
+
readonly languageservice_get_rename: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
336
|
+
readonly languageservice_prepare_rename: (a: number, b: number, c: number, d: number) => number;
|
|
337
|
+
readonly initLogging: (a: number, b: number, c: number) => void;
|
|
338
|
+
readonly setLogLevel: (a: number) => void;
|
|
315
339
|
readonly __wbindgen_export_0: (a: number) => number;
|
|
316
340
|
readonly __wbindgen_export_1: (a: number, b: number, c: number) => number;
|
|
317
341
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
package/lib/web/qsc_wasm.js
CHANGED
|
@@ -324,6 +324,21 @@ export function check_exercise_solution(solution_code, exercise_sources_js, even
|
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
let cachedUint32Memory0 = null;
|
|
328
|
+
|
|
329
|
+
function getUint32Memory0() {
|
|
330
|
+
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
|
|
331
|
+
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
332
|
+
}
|
|
333
|
+
return cachedUint32Memory0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
337
|
+
const ptr = malloc(arg.length * 4);
|
|
338
|
+
getUint32Memory0().set(arg, ptr / 4);
|
|
339
|
+
WASM_VECTOR_LEN = arg.length;
|
|
340
|
+
return ptr;
|
|
341
|
+
}
|
|
327
342
|
/**
|
|
328
343
|
* @param {any} callback
|
|
329
344
|
* @param {number} level
|
|
@@ -349,22 +364,6 @@ export function setLogLevel(level) {
|
|
|
349
364
|
wasm.setLogLevel(level);
|
|
350
365
|
}
|
|
351
366
|
|
|
352
|
-
let cachedUint32Memory0 = null;
|
|
353
|
-
|
|
354
|
-
function getUint32Memory0() {
|
|
355
|
-
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
|
|
356
|
-
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
357
|
-
}
|
|
358
|
-
return cachedUint32Memory0;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function passArray32ToWasm0(arg, malloc) {
|
|
362
|
-
const ptr = malloc(arg.length * 4);
|
|
363
|
-
getUint32Memory0().set(arg, ptr / 4);
|
|
364
|
-
WASM_VECTOR_LEN = arg.length;
|
|
365
|
-
return ptr;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
367
|
function handleError(f, args) {
|
|
369
368
|
try {
|
|
370
369
|
return f.apply(this, args);
|
|
@@ -658,6 +657,31 @@ export class LanguageService {
|
|
|
658
657
|
const ret = wasm.languageservice_get_signature_help(this.ptr, ptr0, len0, offset);
|
|
659
658
|
return takeObject(ret);
|
|
660
659
|
}
|
|
660
|
+
/**
|
|
661
|
+
* @param {string} uri
|
|
662
|
+
* @param {number} offset
|
|
663
|
+
* @param {string} new_name
|
|
664
|
+
* @returns {IWorkspaceEdit}
|
|
665
|
+
*/
|
|
666
|
+
get_rename(uri, offset, new_name) {
|
|
667
|
+
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
668
|
+
const len0 = WASM_VECTOR_LEN;
|
|
669
|
+
const ptr1 = passStringToWasm0(new_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
670
|
+
const len1 = WASM_VECTOR_LEN;
|
|
671
|
+
const ret = wasm.languageservice_get_rename(this.ptr, ptr0, len0, offset, ptr1, len1);
|
|
672
|
+
return takeObject(ret);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* @param {string} uri
|
|
676
|
+
* @param {number} offset
|
|
677
|
+
* @returns {ITextEdit | undefined}
|
|
678
|
+
*/
|
|
679
|
+
prepare_rename(uri, offset) {
|
|
680
|
+
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
681
|
+
const len0 = WASM_VECTOR_LEN;
|
|
682
|
+
const ret = wasm.languageservice_prepare_rename(this.ptr, ptr0, len0, offset);
|
|
683
|
+
return takeObject(ret);
|
|
684
|
+
}
|
|
661
685
|
}
|
|
662
686
|
|
|
663
687
|
async function load(module, imports) {
|
|
@@ -738,6 +762,10 @@ function getImports() {
|
|
|
738
762
|
const ret = getObject(arg0);
|
|
739
763
|
return addHeapObject(ret);
|
|
740
764
|
};
|
|
765
|
+
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
766
|
+
const ret = arg0;
|
|
767
|
+
return addHeapObject(ret);
|
|
768
|
+
};
|
|
741
769
|
imports.wbg.__wbg_new_0232637a3cb0b1a7 = function() {
|
|
742
770
|
const ret = new Error();
|
|
743
771
|
return addHeapObject(ret);
|
|
@@ -749,10 +777,6 @@ function getImports() {
|
|
|
749
777
|
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
750
778
|
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
751
779
|
};
|
|
752
|
-
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
753
|
-
const ret = arg0;
|
|
754
|
-
return addHeapObject(ret);
|
|
755
|
-
};
|
|
756
780
|
imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
|
|
757
781
|
const ret = getObject(arg0) == getObject(arg1);
|
|
758
782
|
return ret;
|
package/lib/web/qsc_wasm_bg.wasm
CHANGED
|
Binary file
|