dot-language-support 1.5.4

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.
Files changed (57) hide show
  1. package/.github/workflows/CD.yml +36 -0
  2. package/.github/workflows/CI.yml +33 -0
  3. package/LICENSE +21 -0
  4. package/README.md +17 -0
  5. package/lib/binder.d.ts +2 -0
  6. package/lib/binder.js +300 -0
  7. package/lib/checker.d.ts +14 -0
  8. package/lib/checker.js +185 -0
  9. package/lib/core.d.ts +1 -0
  10. package/lib/core.js +14 -0
  11. package/lib/error.d.ts +3 -0
  12. package/lib/error.js +14 -0
  13. package/lib/index.d.ts +6 -0
  14. package/lib/index.js +19 -0
  15. package/lib/parser.d.ts +84 -0
  16. package/lib/parser.js +698 -0
  17. package/lib/scanner.d.ts +52 -0
  18. package/lib/scanner.js +580 -0
  19. package/lib/service/codeAction.d.ts +12 -0
  20. package/lib/service/codeAction.js +214 -0
  21. package/lib/service/colorProvider.d.ts +6 -0
  22. package/lib/service/colorProvider.js +74 -0
  23. package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +10 -0
  24. package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +43 -0
  25. package/lib/service/command/ChangeEdgeOpCommand.d.ts +10 -0
  26. package/lib/service/command/ChangeEdgeOpCommand.js +37 -0
  27. package/lib/service/command/ConsolidateDescendantsCommand.d.ts +10 -0
  28. package/lib/service/command/ConsolidateDescendantsCommand.js +106 -0
  29. package/lib/service/command/RemoveSemicolons.d.ts +10 -0
  30. package/lib/service/command/RemoveSemicolons.js +42 -0
  31. package/lib/service/command/common.d.ts +31 -0
  32. package/lib/service/command/common.js +31 -0
  33. package/lib/service/completion.d.ts +4 -0
  34. package/lib/service/completion.js +141 -0
  35. package/lib/service/hover.d.ts +4 -0
  36. package/lib/service/hover.js +123 -0
  37. package/lib/service/interop.d.ts +15 -0
  38. package/lib/service/interop.js +56 -0
  39. package/lib/service/languageFacts.d.ts +659 -0
  40. package/lib/service/languageFacts.js +976 -0
  41. package/lib/service/polyfill.d.ts +16 -0
  42. package/lib/service/polyfill.js +3 -0
  43. package/lib/service/reference.d.ts +5 -0
  44. package/lib/service/reference.js +73 -0
  45. package/lib/service/rename.d.ts +4 -0
  46. package/lib/service/rename.js +49 -0
  47. package/lib/service/service.d.ts +27 -0
  48. package/lib/service/service.js +39 -0
  49. package/lib/service/util.d.ts +11 -0
  50. package/lib/service/util.js +52 -0
  51. package/lib/service/validation.d.ts +4 -0
  52. package/lib/service/validation.js +24 -0
  53. package/lib/types.d.ts +396 -0
  54. package/lib/types.js +74 -0
  55. package/lib/visitor.d.ts +2 -0
  56. package/lib/visitor.js +78 -0
  57. package/package.json +42 -0
@@ -0,0 +1,16 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ export interface ColorInformation {
3
+ range: lst.Range;
4
+ color: Color;
5
+ }
6
+ export interface Color {
7
+ readonly red: number;
8
+ readonly green: number;
9
+ readonly blue: number;
10
+ readonly alpha: number;
11
+ }
12
+ export interface ColorPresentation {
13
+ label: string;
14
+ textEdit?: lst.TextEdit;
15
+ additionalTextEdits?: lst.TextEdit[];
16
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=polyfill.js.map
@@ -0,0 +1,5 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ import { SourceFile } from "../types";
3
+ import { DocumentLike } from "../";
4
+ export declare function findReferences(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position, context: lst.ReferenceContext): lst.Location[];
5
+ export declare function findDefinition(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position): lst.Location | undefined;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findDefinition = exports.findReferences = void 0;
4
+ const __1 = require("../");
5
+ const checker_1 = require("../checker");
6
+ const util_1 = require("./util");
7
+ function findReferences(doc, sourceFile, position, context) {
8
+ if (!sourceFile.symbols)
9
+ throw "sourceFile is not bound";
10
+ const g = sourceFile.graph;
11
+ if (!g)
12
+ return [];
13
+ const offset = doc.offsetAt(position);
14
+ const node = (0, checker_1.findNodeAtOffset)(g, offset);
15
+ if (!node)
16
+ return [];
17
+ if ((0, __1.isIdentifierNode)(node)) {
18
+ const nodeSymbol = node.symbol;
19
+ if (!nodeSymbol)
20
+ throw "node.symbol is not bound";
21
+ const refs = nodeSymbol.references || [];
22
+ let symbolRefs;
23
+ if (context.includeDeclaration) {
24
+ symbolRefs = [nodeSymbol.firstMention, ...refs];
25
+ }
26
+ else {
27
+ if (nodeSymbol.firstMention === node) {
28
+ symbolRefs = refs;
29
+ }
30
+ else {
31
+ symbolRefs = [
32
+ nodeSymbol.firstMention,
33
+ ...refs.filter(r => r !== node),
34
+ ];
35
+ }
36
+ }
37
+ const ranges = (0, util_1.syntaxNodesToRanges)(doc, sourceFile, symbolRefs);
38
+ const uri = doc.uri;
39
+ return ranges.map(range => {
40
+ return { uri, range };
41
+ });
42
+ }
43
+ debugger;
44
+ return [];
45
+ }
46
+ exports.findReferences = findReferences;
47
+ function findDefinition(doc, sourceFile, position) {
48
+ if (!sourceFile.symbols)
49
+ throw "sourceFile is not bound";
50
+ const g = sourceFile.graph;
51
+ if (!g)
52
+ return undefined;
53
+ const offset = doc.offsetAt(position);
54
+ const node = (0, checker_1.findNodeAtOffset)(g, offset);
55
+ if (!node)
56
+ return undefined;
57
+ if ((0, __1.isIdentifierNode)(node)) {
58
+ const nodeSymbol = node.symbol;
59
+ if (!nodeSymbol)
60
+ throw "node.symbol is not bound";
61
+ const refs = nodeSymbol.references || [];
62
+ let symbolRefs;
63
+ const firstMention = nodeSymbol.firstMention;
64
+ if (!firstMention)
65
+ return undefined;
66
+ const range = (0, util_1.syntaxNodeToRange)(doc, sourceFile, firstMention);
67
+ return { uri: doc.uri, range };
68
+ }
69
+ debugger;
70
+ return undefined;
71
+ }
72
+ exports.findDefinition = findDefinition;
73
+ //# sourceMappingURL=reference.js.map
@@ -0,0 +1,4 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ import { SourceFile } from "../types";
3
+ import { DocumentLike } from "../";
4
+ export declare function renameSymbol(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position, newName: string): lst.WorkspaceEdit | undefined;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renameSymbol = void 0;
4
+ const lst = require("vscode-languageserver-types");
5
+ const types_1 = require("../types");
6
+ const checker_1 = require("../checker");
7
+ const __1 = require("../");
8
+ const util_1 = require("./util");
9
+ function renameSymbol(doc, sourceFile, position, newName) {
10
+ if (!sourceFile.symbols)
11
+ throw "sourceFile is not bound";
12
+ if (!newName)
13
+ return undefined;
14
+ const g = sourceFile.graph;
15
+ if (!g)
16
+ return undefined;
17
+ const offset = doc.offsetAt(position);
18
+ const node = (0, checker_1.findNodeAtOffset)(g, offset);
19
+ if (!node)
20
+ return undefined;
21
+ const parent = node.parent;
22
+ if ((0, __1.isIdentifierNode)(node) && isRenamableIdentifier(node) && !!parent && isRenameableNode(parent)) {
23
+ const nodeSymbol = node.symbol;
24
+ if (!nodeSymbol)
25
+ throw "node.symbol is not bound";
26
+ const r = nodeSymbol.references;
27
+ const refs = r ? [nodeSymbol.firstMention, ...r] : [nodeSymbol.firstMention];
28
+ const ranges = (0, util_1.syntaxNodesToRanges)(doc, sourceFile, refs);
29
+ const uri = doc.uri;
30
+ const res = {
31
+ changes: {
32
+ [uri]: ranges.map(r => lst.TextEdit.replace(r, newName)),
33
+ }
34
+ };
35
+ return res;
36
+ }
37
+ debugger;
38
+ return undefined;
39
+ }
40
+ exports.renameSymbol = renameSymbol;
41
+ function isRenameableNode(node) {
42
+ return node.kind === types_1.SyntaxKind.NodeId
43
+ || node.kind === types_1.SyntaxKind.DirectedGraph
44
+ || node.kind === types_1.SyntaxKind.UndirectedGraph;
45
+ }
46
+ function isRenamableIdentifier(node) {
47
+ return node.kind !== types_1.SyntaxKind.QuotedTextIdentifier;
48
+ }
49
+ //# sourceMappingURL=rename.js.map
@@ -0,0 +1,27 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ import { ColorInformation, Color, ColorPresentation } from "./polyfill";
3
+ import { SourceFile, Omit } from "../types";
4
+ export interface DocumentLike {
5
+ positionAt(offset: number): lst.Position;
6
+ offsetAt(position: lst.Position): number;
7
+ readonly uri: string;
8
+ }
9
+ export interface CommandApplication {
10
+ label?: string;
11
+ edit: lst.WorkspaceEdit;
12
+ }
13
+ export interface LanguageService {
14
+ parseDocument(doc: lst.TextDocument | string): SourceFile;
15
+ validateDocument(doc: DocumentLike, sourceFile: SourceFile): lst.Diagnostic[];
16
+ hover(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position): lst.Hover | undefined;
17
+ findReferences(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position, context: lst.ReferenceContext): lst.Location[];
18
+ findDefinition(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position): lst.Location | undefined;
19
+ renameSymbol(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position, newName: string): lst.WorkspaceEdit | undefined;
20
+ getCompletions(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position): lst.CompletionItem[];
21
+ getDocumentColors(doc: DocumentLike, sourceFile: SourceFile): ColorInformation[] | undefined;
22
+ getColorRepresentations(doc: DocumentLike, sourceFile: SourceFile, color: Color, range: lst.Range): ColorPresentation[] | undefined;
23
+ getCodeActions(doc: DocumentLike, sourceFile: SourceFile, range: lst.Range, context: lst.CodeActionContext): lst.Command[] | undefined;
24
+ executeCommand(doc: DocumentLike, sourceFile: SourceFile, command: Omit<lst.Command, "title">): CommandApplication | undefined;
25
+ getAvailableCommands(): string[];
26
+ }
27
+ export declare function createService(): LanguageService;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createService = void 0;
4
+ const __1 = require("../");
5
+ const binder_1 = require("../binder");
6
+ const hover_1 = require("./hover");
7
+ const validation_1 = require("./validation");
8
+ const reference_1 = require("./reference");
9
+ const rename_1 = require("./rename");
10
+ const completion_1 = require("./completion");
11
+ const checker_1 = require("../checker");
12
+ const codeAction_1 = require("./codeAction");
13
+ const colorProvider_1 = require("./colorProvider");
14
+ function parseDocument(doc) {
15
+ const parser = new __1.Parser();
16
+ const content = typeof doc === "string" ? doc : doc.getText();
17
+ const sourceFile = parser.parse(content);
18
+ (0, binder_1.bindSourceFile)(sourceFile);
19
+ (0, checker_1.checkSourceFile)(sourceFile);
20
+ return sourceFile;
21
+ }
22
+ function createService() {
23
+ return {
24
+ parseDocument,
25
+ validateDocument: validation_1.validateDocument,
26
+ hover: hover_1.hover,
27
+ findReferences: reference_1.findReferences,
28
+ findDefinition: reference_1.findDefinition,
29
+ renameSymbol: rename_1.renameSymbol,
30
+ getCompletions: completion_1.getCompletions,
31
+ getDocumentColors: colorProvider_1.getDocumentColors,
32
+ getColorRepresentations: colorProvider_1.getColorRepresentations,
33
+ getCodeActions: codeAction_1.getCodeActions,
34
+ executeCommand: codeAction_1.executeCommand,
35
+ getAvailableCommands: codeAction_1.getAvailableCommands,
36
+ };
37
+ }
38
+ exports.createService = createService;
39
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1,11 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ import { SourceFile, SyntaxNode } from "../types";
3
+ import { DocumentLike } from "../";
4
+ export declare function getStart(sourceFile: SourceFile, node: SyntaxNode): number;
5
+ export declare function syntaxNodesToRanges(doc: DocumentLike, sourceFile: SourceFile, nodes: SyntaxNode[]): lst.Range[];
6
+ export declare function syntaxNodeToRange(doc: DocumentLike, sourceFile: SourceFile, node: SyntaxNode): {
7
+ start: lst.Position;
8
+ end: lst.Position;
9
+ };
10
+ export declare function escapeIdentifierText(text: string): string;
11
+ export declare function assertNever(n: never): never;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNever = exports.escapeIdentifierText = exports.syntaxNodeToRange = exports.syntaxNodesToRanges = exports.getStart = void 0;
4
+ const types_1 = require("../types");
5
+ const scanner_1 = require("../scanner");
6
+ function getStart(sourceFile, node) {
7
+ return getTokenPosOfNode(sourceFile, node);
8
+ }
9
+ exports.getStart = getStart;
10
+ function getTokenPosOfNode(sourceFile, node) {
11
+ if (nodeIsMissing(node))
12
+ return node.pos;
13
+ return (0, scanner_1.skipTrivia)(sourceFile.content, node.pos);
14
+ }
15
+ function nodeIsMissing(node) {
16
+ return node === undefined
17
+ ? true
18
+ : node.pos === node.end && node.pos >= 0 && node.kind !== types_1.SyntaxKind.EndOfFileToken;
19
+ }
20
+ function syntaxNodesToRanges(doc, sourceFile, nodes) {
21
+ return nodes.map(node => syntaxNodeToRange(doc, sourceFile, node));
22
+ }
23
+ exports.syntaxNodesToRanges = syntaxNodesToRanges;
24
+ function syntaxNodeToRange(doc, sourceFile, node) {
25
+ const start = getStart(sourceFile, node);
26
+ return {
27
+ start: doc.positionAt(start),
28
+ end: doc.positionAt(node.end),
29
+ };
30
+ }
31
+ exports.syntaxNodeToRange = syntaxNodeToRange;
32
+ function escapeIdentifierText(text) {
33
+ if (text === "")
34
+ return quote("");
35
+ if (text.includes("\"") || text.includes("\n")) {
36
+ const esc = text
37
+ .replace(/"/, "\\\"")
38
+ .replace(/\n/, "\\\n");
39
+ return quote(esc);
40
+ }
41
+ const ch = text.charCodeAt(0);
42
+ if (!(0, scanner_1.isIdentifierStart)(ch) || text.includes(" "))
43
+ return quote(text);
44
+ return text;
45
+ }
46
+ exports.escapeIdentifierText = escapeIdentifierText;
47
+ const quote = (s) => "\"" + s + "\"";
48
+ function assertNever(n) {
49
+ throw new Error("Never assertion");
50
+ }
51
+ exports.assertNever = assertNever;
52
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1,4 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ import { SourceFile } from "../types";
3
+ import { DocumentLike } from "../";
4
+ export declare function validateDocument(doc: DocumentLike, sourceFile: SourceFile): lst.Diagnostic[];
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateDocument = void 0;
4
+ const error_1 = require("../error");
5
+ function convertDiagnostic(document, source) {
6
+ return {
7
+ range: {
8
+ start: document.positionAt(source.start),
9
+ end: document.positionAt(source.end),
10
+ },
11
+ severity: source.category,
12
+ code: (0, error_1.formatError)(source.code),
13
+ source: error_1.diagnosicSource,
14
+ message: source.message,
15
+ };
16
+ }
17
+ function validateDocument(doc, sourceFile) {
18
+ const diagnostics = sourceFile.diagnostics;
19
+ if (!diagnostics || diagnostics.length <= 0)
20
+ return [];
21
+ return diagnostics.map(d => convertDiagnostic(doc, d));
22
+ }
23
+ exports.validateDocument = validateDocument;
24
+ //# sourceMappingURL=validation.js.map