@microsoft/powerquery-language-services 0.5.0 → 0.5.1

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.
@@ -0,0 +1,3 @@
1
+ import * as PQP from "@microsoft/powerquery-parser";
2
+ import { DocumentSymbol } from "./commonTypes";
3
+ export declare function getDocumentSymbols(nodeIdMapCollection: PQP.Parser.NodeIdMap.Collection, cancellationToken: PQP.ICancellationToken): DocumentSymbol[];
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT license.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getDocumentSymbols = void 0;
6
+ const parser_1 = require("@microsoft/powerquery-parser/lib/powerquery-parser/parser");
7
+ const InspectionUtils = require("./inspectionUtils");
8
+ const commonTypes_1 = require("./commonTypes");
9
+ function getDocumentSymbols(nodeIdMapCollection, cancellationToken) {
10
+ const currentSymbols = [];
11
+ const parentSymbolById = new Map();
12
+ addIdentifierPairedExpressionSymbols(nodeIdMapCollection, currentSymbols, parentSymbolById, cancellationToken);
13
+ addRecordSymbols(nodeIdMapCollection, currentSymbols, parentSymbolById, cancellationToken);
14
+ return currentSymbols;
15
+ }
16
+ exports.getDocumentSymbols = getDocumentSymbols;
17
+ function addIdentifierPairedExpressionSymbols(nodeIdMapCollection, currentSymbols, parentSymbolById, cancellationToken) {
18
+ var _a;
19
+ const identifierPairedExpressionIds = (_a = nodeIdMapCollection.idsByNodeKind.get("IdentifierPairedExpression" /* IdentifierPairedExpression */)) !== null && _a !== void 0 ? _a : new Set();
20
+ for (const nodeId of identifierPairedExpressionIds) {
21
+ cancellationToken.throwIfCancelled();
22
+ const xorNode = parser_1.NodeIdMapUtils.assertGetXorChecked(nodeIdMapCollection, nodeId, "IdentifierPairedExpression" /* IdentifierPairedExpression */);
23
+ if (!parser_1.XorNodeUtils.isAstXor(xorNode)) {
24
+ continue;
25
+ }
26
+ const astNode = xorNode.node;
27
+ const documentSymbol = InspectionUtils.getSymbolForIdentifierPairedExpression(astNode);
28
+ addDocumentSymbols(nodeIdMapCollection, parentSymbolById, nodeId, currentSymbols, documentSymbol);
29
+ parentSymbolById.set(nodeId, documentSymbol);
30
+ }
31
+ }
32
+ function addRecordSymbols(nodeIdMapCollection, currentSymbols, parentSymbolById, cancellationToken) {
33
+ var _a, _b;
34
+ const recordIdCollections = [
35
+ (_a = nodeIdMapCollection.idsByNodeKind.get("RecordExpression" /* RecordExpression */)) !== null && _a !== void 0 ? _a : new Set(),
36
+ (_b = nodeIdMapCollection.idsByNodeKind.get("RecordLiteral" /* RecordLiteral */)) !== null && _b !== void 0 ? _b : new Set(),
37
+ ];
38
+ for (const collection of recordIdCollections) {
39
+ for (const nodeId of collection) {
40
+ cancellationToken.throwIfCancelled();
41
+ const xorNode = parser_1.NodeIdMapUtils.assertGetXorChecked(nodeIdMapCollection, nodeId, ["RecordExpression" /* RecordExpression */, "RecordLiteral" /* RecordLiteral */]);
42
+ if (!parser_1.XorNodeUtils.isAstXor(xorNode)) {
43
+ continue;
44
+ }
45
+ const astNode = xorNode.node;
46
+ // Process the record if the immediate parent is a Struct
47
+ const parentId = nodeIdMapCollection.parentIdById.get(astNode.id);
48
+ const parentSymbol = parentId ? parentSymbolById.get(parentId) : undefined;
49
+ if (parentSymbol && parentSymbol.kind === commonTypes_1.SymbolKind.Struct) {
50
+ const fieldSymbols = InspectionUtils.getSymbolsForRecord(astNode);
51
+ if (fieldSymbols.length > 0) {
52
+ addDocumentSymbols(nodeIdMapCollection, parentSymbolById, astNode.id, currentSymbols, ...fieldSymbols);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ function addDocumentSymbols(nodeIdMapCollection, parentSymbolById, nodeId, currentSymbols, ...newSymbols) {
59
+ const parentSymbol = findParentSymbol(nodeIdMapCollection, parentSymbolById, nodeId);
60
+ if (parentSymbol) {
61
+ if (!parentSymbol.children) {
62
+ parentSymbol.children = [];
63
+ }
64
+ parentSymbol.children.push(...newSymbols);
65
+ return;
66
+ }
67
+ // Add to the top level
68
+ currentSymbols.push(...newSymbols);
69
+ }
70
+ function findParentSymbol(nodeIdMapCollection, parentSymbolById, nodeId) {
71
+ // Get parent for current node
72
+ const parentNodeId = nodeIdMapCollection.parentIdById.get(nodeId);
73
+ if (!parentNodeId) {
74
+ // No more parents to check
75
+ return undefined;
76
+ }
77
+ let parentSymbol = parentSymbolById.get(parentNodeId);
78
+ if (!parentSymbol) {
79
+ parentSymbol = findParentSymbol(nodeIdMapCollection, parentSymbolById, parentNodeId);
80
+ }
81
+ return parentSymbol;
82
+ }
83
+ //# sourceMappingURL=documentSymbols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentSymbols.js","sourceRoot":"","sources":["../../src/powerquery-language-services/documentSymbols.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,sFAKmE;AAGnE,qDAAqD;AACrD,+CAA2D;AAE3D,SAAgB,kBAAkB,CAC9B,mBAAoD,EACpD,iBAAyC;IAEzC,MAAM,cAAc,GAAqB,EAAE,CAAC;IAC5C,MAAM,gBAAgB,GAAgC,IAAI,GAAG,EAAE,CAAC;IAEhE,oCAAoC,CAAC,mBAAmB,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IAC/G,gBAAgB,CAAC,mBAAmB,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IAE3F,OAAO,cAAc,CAAC;AAC1B,CAAC;AAXD,gDAWC;AAED,SAAS,oCAAoC,CACzC,mBAAyC,EACzC,cAAgC,EAChC,gBAA6C,EAC7C,iBAAyC;;IAEzC,MAAM,6BAA6B,GAC/B,MAAA,mBAAmB,CAAC,aAAa,CAAC,GAAG,+DAAyC,mCAAI,IAAI,GAAG,EAAE,CAAC;IAEhG,KAAK,MAAM,MAAM,IAAI,6BAA6B,EAAE;QAChD,iBAAiB,CAAC,gBAAgB,EAAE,CAAC;Q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Y,GAAG,gBAAgB,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;KACxF;IAED,OAAO,YAAY,CAAC;AACxB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { TextDocument, TextDocumentContentChangeEvent } from "vscode-languageserver-textdocument";
1
+ import { TextDocument } from "vscode-languageserver-textdocument";
2
2
  export * as CommonTypesUtils from "./commonTypesUtils";
3
3
  export * as Inspection from "./inspection";
4
4
  export * as InspectionUtils from "./inspectionUtils";
@@ -7,6 +7,7 @@ export * as TraceUtils from "./traceUtils";
7
7
  export * from "./analysis";
8
8
  export * from "./commonTypes";
9
9
  export * from "./diagnosticErrorCode";
10
+ export * from "./documentSymbols";
10
11
  export * from "./formatter";
11
12
  export * from "./inspectionSettings";
12
13
  export * from "./jaroWinkler";
@@ -14,7 +15,4 @@ export * from "./library";
14
15
  export * from "./providers";
15
16
  export * from "./trace";
16
17
  export * from "./validate";
17
- export * from "./workspaceCache";
18
18
  export declare function createTextDocument(id: string, version: number, content: string): TextDocument;
19
- export declare function documentUpdated(document: TextDocument, changes: ReadonlyArray<TextDocumentContentChangeEvent>, version: number): void;
20
- export declare function documentClosed(document: TextDocument): void;
@@ -16,9 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.documentClosed = exports.documentUpdated = exports.createTextDocument = exports.TraceUtils = exports.PositionUtils = exports.InspectionUtils = exports.Inspection = exports.CommonTypesUtils = void 0;
19
+ exports.createTextDocument = exports.TraceUtils = exports.PositionUtils = exports.InspectionUtils = exports.Inspection = exports.CommonTypesUtils = void 0;
20
20
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
21
- const workspaceCache_1 = require("./workspaceCache");
22
21
  exports.CommonTypesUtils = require("./commonTypesUtils");
23
22
  exports.Inspection = require("./inspection");
24
23
  exports.InspectionUtils = require("./inspectionUtils");
@@ -27,6 +26,7 @@ exports.TraceUtils = require("./traceUtils");
27
26
  __exportStar(require("./analysis"), exports);
28
27
  __exportStar(require("./commonTypes"), exports);
29
28
  __exportStar(require("./diagnosticErrorCode"), exports);
29
+ __exportStar(require("./documentSymbols"), exports);
30
30
  __exportStar(require("./formatter"), exports);
31
31
  __exportStar(require("./inspectionSettings"), exports);
32
32
  __exportStar(require("./jaroWinkler"), exports);
@@ -34,17 +34,8 @@ __exportStar(require("./library"), exports);
34
34
  __exportStar(require("./providers"), exports);
35
35
  __exportStar(require("./trace"), exports);
36
36
  __exportStar(require("./validate"), exports);
37
- __exportStar(require("./workspaceCache"), exports);
38
37
  function createTextDocument(id, version, content) {
39
38
  return vscode_languageserver_textdocument_1.TextDocument.create(id, "powerquery", version, content);
40
39
  }
41
40
  exports.createTextDocument = createTextDocument;
42
- function documentUpdated(document, changes, version) {
43
- workspaceCache_1.WorkspaceCacheUtils.update(document, changes, version);
44
- }
45
- exports.documentUpdated = documentUpdated;
46
- function documentClosed(document) {
47
- workspaceCache_1.WorkspaceCacheUtils.close(document);
48
- }
49
- exports.documentClosed = documentClosed;
50
41
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/powerquery-language-services/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;;;;;;;;AAElC,2FAAkG;AAClG,qDAAuD;AAEvD,yDAAuD;AACvD,6CAA2C;AAC3C,uDAAqD;AACrD,mDAAiD;AACjD,6CAA2C;AAC3C,6CAA2B;AAC3B,gDAA8B;AAC9B,wDAAsC;AACtC,8CAA4B;AAC5B,uDAAqC;AACrC,gDAA8B;AAC9B,4CAA0B;AAC1B,8CAA4B;AAC5B,0CAAwB;AACxB,6CAA2B;AAC3B,mDAAiC;AAEjC,SAAgB,kBAAkB,CAAC,EAAU,EAAE,OAAe,EAAE,OAAe;IAC3E,OAAO,iDAAY,CAAC,MAAM,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC;AAFD,gDAEC;AAED,SAAgB,eAAe,CAC3B,QAAsB,EACtB,OAAsD,EACtD,OAAe;IAEf,oCAAmB,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAND,0CAMC;AAED,SAAgB,cAAc,CAAC,QAAsB;IACjD,oCAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAFD,wCAEC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/powerquery-language-services/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;;;;;;;;AAElC,2FAAkE;AAElE,yDAAuD;AACvD,6CAA2C;AAC3C,uDAAqD;AACrD,mDAAiD;AACjD,6CAA2C;AAC3C,6CAA2B;AAC3B,gDAA8B;AAC9B,wDAAsC;AACtC,oDAAkC;AAClC,8CAA4B;AAC5B,uDAAqC;AACrC,gDAA8B;AAC9B,4CAA0B;AAC1B,8CAA4B;AAC5B,0CAAwB;AACxB,6CAA2B;AAE3B,SAAgB,kBAAkB,CAAC,EAAU,EAAE,OAAe,EAAE,OAAe;IAC3E,OAAO,iDAAY,CAAC,MAAM,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC;AAFD,gDAEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/powerquery-language-services",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "author": "Microsoft",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -1,2 +0,0 @@
1
- export * as WorkspaceCache from "./workspaceCache";
2
- export * as WorkspaceCacheUtils from "./workspaceCacheUtils";
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorkspaceCacheUtils = exports.WorkspaceCache = void 0;
4
- exports.WorkspaceCache = require("./workspaceCache");
5
- exports.WorkspaceCacheUtils = require("./workspaceCacheUtils");
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/powerquery-language-services/workspaceCache/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AACnD,+DAA6D"}
@@ -1,9 +0,0 @@
1
- import * as PQP from "@microsoft/powerquery-parser";
2
- import { Inspection } from "..";
3
- export interface CacheCollection {
4
- lex: Promise<PQP.Task.TriedLexTask> | undefined;
5
- parse: Promise<PQP.Task.TriedParseTask | undefined> | undefined;
6
- readonly inspectionByPosition: Map<string, Promise<Inspection.Inspected> | undefined>;
7
- readonly typeCache: Inspection.TypeCache;
8
- readonly version: number;
9
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT license.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- //# sourceMappingURL=workspaceCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workspaceCache.js","sourceRoot":"","sources":["../../../src/powerquery-language-services/workspaceCache/workspaceCache.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC"}
@@ -1,13 +0,0 @@
1
- import * as PQP from "@microsoft/powerquery-parser";
2
- import type { TextDocument, TextDocumentContentChangeEvent } from "vscode-languageserver-textdocument";
3
- import type { Position } from "vscode-languageserver-types";
4
- import { CacheCollection } from "./workspaceCache";
5
- import { Inspection } from "..";
6
- import { InspectionSettings } from "../inspectionSettings";
7
- export declare function close(textDocument: TextDocument): void;
8
- export declare function getTypeCache(textDocument: TextDocument, isWorkspaceCacheAllowed: boolean): Inspection.TypeCache;
9
- export declare function getOrCreateCacheCollection(textDocument: TextDocument, isWorkspaceCacheAllowed: boolean): CacheCollection;
10
- export declare function getOrCreateLexPromise(textDocument: TextDocument, lexSettings: PQP.LexSettings, isWorkspaceCacheAllowed: boolean): Promise<PQP.Task.TriedLexTask>;
11
- export declare function getOrCreateParsePromise(textDocument: TextDocument, lexAndParseSettings: PQP.LexSettings & PQP.ParseSettings, isWorkspaceCacheAllowed: boolean): Promise<PQP.Task.TriedParseTask | undefined>;
12
- export declare function getOrCreateInspectedPromise(textDocument: TextDocument, inspectionSettings: InspectionSettings, position: Position): Promise<Inspection.Inspected | undefined>;
13
- export declare function update(textDocument: TextDocument, _changes: ReadonlyArray<TextDocumentContentChangeEvent>, _version: number): void;
@@ -1,130 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT license.
4
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
- return new (P || (P = Promise))(function (resolve, reject) {
7
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
- step((generator = generator.apply(thisArg, _arguments || [])).next());
11
- });
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.update = exports.getOrCreateInspectedPromise = exports.getOrCreateParsePromise = exports.getOrCreateLexPromise = exports.getOrCreateCacheCollection = exports.getTypeCache = exports.close = void 0;
15
- const PQP = require("@microsoft/powerquery-parser");
16
- const __1 = require("..");
17
- const inspection_1 = require("../inspection");
18
- const CacheCollectionByCacheKey = new Map();
19
- function close(textDocument) {
20
- const collectionCacheKey = createCollectionCacheKey(textDocument);
21
- CacheCollectionByCacheKey.delete(collectionCacheKey);
22
- }
23
- exports.close = close;
24
- function getTypeCache(textDocument, isWorkspaceCacheAllowed) {
25
- if (!isWorkspaceCacheAllowed) {
26
- return inspection_1.TypeCacheUtils.createEmptyCache();
27
- }
28
- const cacheCollection = getOrCreateCacheCollection(textDocument, isWorkspaceCacheAllowed);
29
- return cacheCollection.typeCache;
30
- }
31
- exports.getTypeCache = getTypeCache;
32
- function getOrCreateCacheCollection(textDocument, isWorkspaceCacheAllowed) {
33
- if (!isWorkspaceCacheAllowed) {
34
- return createEmptyCacheCollection(textDocument.version);
35
- }
36
- const cacheKey = createCollectionCacheKey(textDocument);
37
- const cacheCollection = CacheCollectionByCacheKey.get(cacheKey);
38
- if (cacheCollection !== undefined) {
39
- if (textDocument.version === cacheCollection.version) {
40
- return cacheCollection;
41
- }
42
- else {
43
- close(textDocument);
44
- }
45
- }
46
- const newCacheCollection = createEmptyCacheCollection(textDocument.version);
47
- if (isWorkspaceCacheAllowed) {
48
- CacheCollectionByCacheKey.set(cacheKey, newCacheCollection);
49
- }
50
- return newCacheCollection;
51
- }
52
- exports.getOrCreateCacheCollection = getOrCreateCacheCollection;
53
- function getOrCreateLexPromise(textDocument, lexSettings, isWorkspaceCacheAllowed) {
54
- const cacheCollection = getOrCreateCacheCollection(textDocument, isWorkspaceCacheAllowed);
55
- if (cacheCollection.lex) {
56
- return cacheCollection.lex;
57
- }
58
- const lexPromise = Promise.resolve(PQP.TaskUtils.tryLex(lexSettings, textDocument.getText()));
59
- cacheCollection.lex = lexPromise;
60
- return lexPromise;
61
- }
62
- exports.getOrCreateLexPromise = getOrCreateLexPromise;
63
- function getOrCreateParsePromise(textDocument, lexAndParseSettings, isWorkspaceCacheAllowed) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const cacheCollection = getOrCreateCacheCollection(textDocument, isWorkspaceCacheAllowed);
66
- if (cacheCollection.parse) {
67
- return cacheCollection.parse;
68
- }
69
- const triedLexPromise = getOrCreateLexPromise(textDocument, lexAndParseSettings, isWorkspaceCacheAllowed);
70
- const triedLex = yield triedLexPromise;
71
- if (PQP.TaskUtils.isError(triedLex)) {
72
- cacheCollection.parse = Promise.resolve(undefined);
73
- return undefined;
74
- }
75
- cacheCollection.parse = PQP.TaskUtils.tryParse(lexAndParseSettings, triedLex.lexerSnapshot);
76
- return cacheCollection.parse;
77
- });
78
- }
79
- exports.getOrCreateParsePromise = getOrCreateParsePromise;
80
- function getOrCreateInspectedPromise(textDocument, inspectionSettings, position) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- const cacheCollection = getOrCreateCacheCollection(textDocument, inspectionSettings.isWorkspaceCacheAllowed);
83
- const positionMapKey = createInspectionByPositionKey(position);
84
- if (cacheCollection.inspectionByPosition.has(positionMapKey)) {
85
- return cacheCollection.inspectionByPosition.get(positionMapKey);
86
- }
87
- const triedParsePromise = getOrCreateParsePromise(textDocument, inspectionSettings, inspectionSettings.isWorkspaceCacheAllowed);
88
- const triedParseTask = yield triedParsePromise;
89
- if (triedParseTask === undefined ||
90
- !PQP.TaskUtils.isParseStage(triedParseTask) ||
91
- PQP.TaskUtils.isParseStageCommonError(triedParseTask)) {
92
- if (inspectionSettings.isWorkspaceCacheAllowed) {
93
- cacheCollection.inspectionByPosition.set(positionMapKey, undefined);
94
- }
95
- return undefined;
96
- }
97
- let parseState;
98
- if (PQP.TaskUtils.isParseStageOk(triedParseTask)) {
99
- parseState = triedParseTask.parseState;
100
- }
101
- else if (PQP.TaskUtils.isParseStageParseError(triedParseTask)) {
102
- parseState = triedParseTask.parseState;
103
- }
104
- else {
105
- throw PQP.Assert.isNever(triedParseTask);
106
- }
107
- return __1.Inspection.inspect(inspectionSettings, parseState, PQP.TaskUtils.isParseStageParseError(triedParseTask) ? triedParseTask.error : undefined, position, cacheCollection.typeCache);
108
- });
109
- }
110
- exports.getOrCreateInspectedPromise = getOrCreateInspectedPromise;
111
- function update(textDocument, _changes, _version) {
112
- close(textDocument);
113
- }
114
- exports.update = update;
115
- function createCollectionCacheKey(textDocument) {
116
- return `${textDocument.uri}`;
117
- }
118
- function createEmptyCacheCollection(version) {
119
- return {
120
- lex: undefined,
121
- parse: undefined,
122
- inspectionByPosition: new Map(),
123
- typeCache: inspection_1.TypeCacheUtils.createEmptyCache(),
124
- version,
125
- };
126
- }
127
- function createInspectionByPositionKey(position) {
128
- return `${position.character};${position.line}`;
129
- }
130
- //# sourceMappingURL=workspaceCacheUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workspaceCacheUtils.js","sourceRoot":"","sources":["../../../src/powerquery-language-services/workspaceCache/workspaceCacheUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;;;AAElC,oDAAoD;AAKpD,0BAAgC;AAEhC,8CAA+C;AAE/C,MAAM,yBAAyB,GAAiC,IAAI,GAAG,EAAE,CAAC;AAE1E,SAAgB,KAAK,CAAC,YAA0B;IAC5C,MAAM,kBAAkB,GAAW,wBAAwB,CAAC,YAAY,CAAC,CAAC;IAC1E,yBAAyB,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;AACzD,CAAC;AAHD,sBAGC;AAED,SAAgB,YAAY,CAAC,YAA0B,EAAE,uBAAgC;IACrF,IAAI,CAAC,uBAAuB,EAAE;QAC1B,OAAO,2BAAc,CAAC,gBAAgB,EAAE,CAAC;KAC5C;IAED,MAAM,eAAe,GAAoB,0BAA0B,CAAC,YAAY,EAAE,uBAAuB,CAAC,CAAC;IAE3G,OAAO,eAAe,CAAC,SAAS,CAAC;AACrC,CAAC;AARD,oCAQC;AAED,SAAgB,0BAA0B,CACtC,YAA0B,EAC1B,uBAAgC;IAEhC,IAAI,CAAC,uBAAuB,EAAE;QAC1B,OAAO,0BAA0B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;KAC3D;IAED,MAAM,QAAQ,GAAW,wBAAwB,CAAC,YAAY,CAAC,CAAC;IAChE,MAAM,eAAe,GAAgC,yBAAyB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE7F,IAAI,eAAe,KAAK,SAAS,EAAE;QAC/B,IAAI,YAAY,CAAC,OAAO,KAAK,eAAe,CAAC,OAAO,EAAE;YAClD,OAAO,eAAe,CAAC;SAC1B;aAAM;YACH,KAAK,C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