@reqlan/language 1.4.0
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/README.md +24 -0
- package/out/file-path-rewrite.d.ts +25 -0
- package/out/file-path-rewrite.js +56 -0
- package/out/file-path-rewrite.js.map +1 -0
- package/out/generated/ast.d.ts +1157 -0
- package/out/generated/ast.js +980 -0
- package/out/generated/ast.js.map +1 -0
- package/out/generated/grammar.d.ts +7 -0
- package/out/generated/grammar.js +3071 -0
- package/out/generated/grammar.js.map +1 -0
- package/out/generated/module.d.ts +20 -0
- package/out/generated/module.js +32 -0
- package/out/generated/module.js.map +1 -0
- package/out/index.d.ts +34 -0
- package/out/index.js +35 -0
- package/out/index.js.map +1 -0
- package/out/reqlan-attribute-catalog.d.ts +19 -0
- package/out/reqlan-attribute-catalog.js +87 -0
- package/out/reqlan-attribute-catalog.js.map +1 -0
- package/out/reqlan-code-action-provider.d.ts +55 -0
- package/out/reqlan-code-action-provider.js +269 -0
- package/out/reqlan-code-action-provider.js.map +1 -0
- package/out/reqlan-code-lens-provider.d.ts +13 -0
- package/out/reqlan-code-lens-provider.js +27 -0
- package/out/reqlan-code-lens-provider.js.map +1 -0
- package/out/reqlan-code-lens-settings.d.ts +34 -0
- package/out/reqlan-code-lens-settings.js +12 -0
- package/out/reqlan-code-lens-settings.js.map +1 -0
- package/out/reqlan-comment-resolver.d.ts +35 -0
- package/out/reqlan-comment-resolver.js +308 -0
- package/out/reqlan-comment-resolver.js.map +1 -0
- package/out/reqlan-completion-context.d.ts +46 -0
- package/out/reqlan-completion-context.js +244 -0
- package/out/reqlan-completion-context.js.map +1 -0
- package/out/reqlan-completion-provider.d.ts +41 -0
- package/out/reqlan-completion-provider.js +317 -0
- package/out/reqlan-completion-provider.js.map +1 -0
- package/out/reqlan-definition-provider.d.ts +31 -0
- package/out/reqlan-definition-provider.js +240 -0
- package/out/reqlan-definition-provider.js.map +1 -0
- package/out/reqlan-document-highlight-provider.d.ts +10 -0
- package/out/reqlan-document-highlight-provider.js +11 -0
- package/out/reqlan-document-highlight-provider.js.map +1 -0
- package/out/reqlan-document-link-provider.d.ts +14 -0
- package/out/reqlan-document-link-provider.js +24 -0
- package/out/reqlan-document-link-provider.js.map +1 -0
- package/out/reqlan-embedded-file-references.d.ts +11 -0
- package/out/reqlan-embedded-file-references.js +50 -0
- package/out/reqlan-embedded-file-references.js.map +1 -0
- package/out/reqlan-file-link-resolver.d.ts +44 -0
- package/out/reqlan-file-link-resolver.js +347 -0
- package/out/reqlan-file-link-resolver.js.map +1 -0
- package/out/reqlan-file-references.d.ts +15 -0
- package/out/reqlan-file-references.js +72 -0
- package/out/reqlan-file-references.js.map +1 -0
- package/out/reqlan-grammar-config.d.ts +5 -0
- package/out/reqlan-grammar-config.js +9 -0
- package/out/reqlan-grammar-config.js.map +1 -0
- package/out/reqlan-idea-reference-site.d.ts +14 -0
- package/out/reqlan-idea-reference-site.js +47 -0
- package/out/reqlan-idea-reference-site.js.map +1 -0
- package/out/reqlan-idea-summary.d.ts +6 -0
- package/out/reqlan-idea-summary.js +134 -0
- package/out/reqlan-idea-summary.js.map +1 -0
- package/out/reqlan-ignore-error.d.ts +10 -0
- package/out/reqlan-ignore-error.js +42 -0
- package/out/reqlan-ignore-error.js.map +1 -0
- package/out/reqlan-import-bindings.d.ts +12 -0
- package/out/reqlan-import-bindings.js +65 -0
- package/out/reqlan-import-bindings.js.map +1 -0
- package/out/reqlan-import-edits.d.ts +17 -0
- package/out/reqlan-import-edits.js +96 -0
- package/out/reqlan-import-edits.js.map +1 -0
- package/out/reqlan-imports.d.ts +22 -0
- package/out/reqlan-imports.js +61 -0
- package/out/reqlan-imports.js.map +1 -0
- package/out/reqlan-inbound-reference-inlay-label.d.ts +27 -0
- package/out/reqlan-inbound-reference-inlay-label.js +142 -0
- package/out/reqlan-inbound-reference-inlay-label.js.map +1 -0
- package/out/reqlan-inlay-hint-provider.d.ts +15 -0
- package/out/reqlan-inlay-hint-provider.js +54 -0
- package/out/reqlan-inlay-hint-provider.js.map +1 -0
- package/out/reqlan-inlay-hint-settings.d.ts +10 -0
- package/out/reqlan-inlay-hint-settings.js +10 -0
- package/out/reqlan-inlay-hint-settings.js.map +1 -0
- package/out/reqlan-linker.d.ts +26 -0
- package/out/reqlan-linker.js +83 -0
- package/out/reqlan-linker.js.map +1 -0
- package/out/reqlan-markdown-links.d.ts +28 -0
- package/out/reqlan-markdown-links.js +113 -0
- package/out/reqlan-markdown-links.js.map +1 -0
- package/out/reqlan-module.d.ts +41 -0
- package/out/reqlan-module.js +78 -0
- package/out/reqlan-module.js.map +1 -0
- package/out/reqlan-name-catalog.d.ts +23 -0
- package/out/reqlan-name-catalog.js +63 -0
- package/out/reqlan-name-catalog.js.map +1 -0
- package/out/reqlan-name-provider.d.ts +10 -0
- package/out/reqlan-name-provider.js +38 -0
- package/out/reqlan-name-provider.js.map +1 -0
- package/out/reqlan-namespace-import-links.d.ts +10 -0
- package/out/reqlan-namespace-import-links.js +69 -0
- package/out/reqlan-namespace-import-links.js.map +1 -0
- package/out/reqlan-path-completion.d.ts +50 -0
- package/out/reqlan-path-completion.js +304 -0
- package/out/reqlan-path-completion.js.map +1 -0
- package/out/reqlan-path-references.d.ts +5 -0
- package/out/reqlan-path-references.js +124 -0
- package/out/reqlan-path-references.js.map +1 -0
- package/out/reqlan-path-resolve.d.ts +81 -0
- package/out/reqlan-path-resolve.js +245 -0
- package/out/reqlan-path-resolve.js.map +1 -0
- package/out/reqlan-quoted-strings.d.ts +9 -0
- package/out/reqlan-quoted-strings.js +26 -0
- package/out/reqlan-quoted-strings.js.map +1 -0
- package/out/reqlan-reference-at-position.d.ts +20 -0
- package/out/reqlan-reference-at-position.js +89 -0
- package/out/reqlan-reference-at-position.js.map +1 -0
- package/out/reqlan-reference-code-lens.d.ts +32 -0
- package/out/reqlan-reference-code-lens.js +240 -0
- package/out/reqlan-reference-code-lens.js.map +1 -0
- package/out/reqlan-reference-search-site.d.ts +34 -0
- package/out/reqlan-reference-search-site.js +136 -0
- package/out/reqlan-reference-search-site.js.map +1 -0
- package/out/reqlan-references.d.ts +16 -0
- package/out/reqlan-references.js +51 -0
- package/out/reqlan-references.js.map +1 -0
- package/out/reqlan-scope.d.ts +25 -0
- package/out/reqlan-scope.js +259 -0
- package/out/reqlan-scope.js.map +1 -0
- package/out/reqlan-semantic-token-provider.d.ts +8 -0
- package/out/reqlan-semantic-token-provider.js +91 -0
- package/out/reqlan-semantic-token-provider.js.map +1 -0
- package/out/reqlan-token-builder.d.ts +12 -0
- package/out/reqlan-token-builder.js +459 -0
- package/out/reqlan-token-builder.js.map +1 -0
- package/out/reqlan-validator.d.ts +25 -0
- package/out/reqlan-validator.js +119 -0
- package/out/reqlan-validator.js.map +1 -0
- package/out/reqlan-workspace-attribute-catalog.d.ts +6 -0
- package/out/reqlan-workspace-attribute-catalog.js +54 -0
- package/out/reqlan-workspace-attribute-catalog.js.map +1 -0
- package/out/src/file-path-rewrite.d.ts +25 -0
- package/out/src/file-path-rewrite.js +56 -0
- package/out/src/file-path-rewrite.js.map +1 -0
- package/out/src/generated/ast.d.ts +1173 -0
- package/out/src/generated/ast.js +994 -0
- package/out/src/generated/ast.js.map +1 -0
- package/out/src/generated/grammar.d.ts +7 -0
- package/out/src/generated/grammar.js +3045 -0
- package/out/src/generated/grammar.js.map +1 -0
- package/out/src/generated/module.d.ts +20 -0
- package/out/src/generated/module.js +32 -0
- package/out/src/generated/module.js.map +1 -0
- package/out/src/index.d.ts +29 -0
- package/out/src/index.js +30 -0
- package/out/src/index.js.map +1 -0
- package/out/src/reqlan-attribute-catalog.d.ts +19 -0
- package/out/src/reqlan-attribute-catalog.js +87 -0
- package/out/src/reqlan-attribute-catalog.js.map +1 -0
- package/out/src/reqlan-code-action-provider.d.ts +34 -0
- package/out/src/reqlan-code-action-provider.js +206 -0
- package/out/src/reqlan-code-action-provider.js.map +1 -0
- package/out/src/reqlan-comment-resolver.d.ts +35 -0
- package/out/src/reqlan-comment-resolver.js +308 -0
- package/out/src/reqlan-comment-resolver.js.map +1 -0
- package/out/src/reqlan-completion-context.d.ts +46 -0
- package/out/src/reqlan-completion-context.js +244 -0
- package/out/src/reqlan-completion-context.js.map +1 -0
- package/out/src/reqlan-completion-provider.d.ts +41 -0
- package/out/src/reqlan-completion-provider.js +320 -0
- package/out/src/reqlan-completion-provider.js.map +1 -0
- package/out/src/reqlan-definition-provider.d.ts +31 -0
- package/out/src/reqlan-definition-provider.js +240 -0
- package/out/src/reqlan-definition-provider.js.map +1 -0
- package/out/src/reqlan-document-highlight-provider.d.ts +10 -0
- package/out/src/reqlan-document-highlight-provider.js +11 -0
- package/out/src/reqlan-document-highlight-provider.js.map +1 -0
- package/out/src/reqlan-document-link-provider.d.ts +14 -0
- package/out/src/reqlan-document-link-provider.js +24 -0
- package/out/src/reqlan-document-link-provider.js.map +1 -0
- package/out/src/reqlan-embedded-file-references.d.ts +11 -0
- package/out/src/reqlan-embedded-file-references.js +50 -0
- package/out/src/reqlan-embedded-file-references.js.map +1 -0
- package/out/src/reqlan-file-link-resolver.d.ts +44 -0
- package/out/src/reqlan-file-link-resolver.js +347 -0
- package/out/src/reqlan-file-link-resolver.js.map +1 -0
- package/out/src/reqlan-file-references.d.ts +15 -0
- package/out/src/reqlan-file-references.js +72 -0
- package/out/src/reqlan-file-references.js.map +1 -0
- package/out/src/reqlan-grammar-config.d.ts +5 -0
- package/out/src/reqlan-grammar-config.js +9 -0
- package/out/src/reqlan-grammar-config.js.map +1 -0
- package/out/src/reqlan-idea-summary.d.ts +6 -0
- package/out/src/reqlan-idea-summary.js +78 -0
- package/out/src/reqlan-idea-summary.js.map +1 -0
- package/out/src/reqlan-ignore-error.d.ts +10 -0
- package/out/src/reqlan-ignore-error.js +42 -0
- package/out/src/reqlan-ignore-error.js.map +1 -0
- package/out/src/reqlan-import-bindings.d.ts +12 -0
- package/out/src/reqlan-import-bindings.js +65 -0
- package/out/src/reqlan-import-bindings.js.map +1 -0
- package/out/src/reqlan-import-edits.d.ts +17 -0
- package/out/src/reqlan-import-edits.js +96 -0
- package/out/src/reqlan-import-edits.js.map +1 -0
- package/out/src/reqlan-imports.d.ts +22 -0
- package/out/src/reqlan-imports.js +61 -0
- package/out/src/reqlan-imports.js.map +1 -0
- package/out/src/reqlan-inbound-reference-inlay-label.d.ts +23 -0
- package/out/src/reqlan-inbound-reference-inlay-label.js +128 -0
- package/out/src/reqlan-inbound-reference-inlay-label.js.map +1 -0
- package/out/src/reqlan-inlay-hint-provider.d.ts +15 -0
- package/out/src/reqlan-inlay-hint-provider.js +54 -0
- package/out/src/reqlan-inlay-hint-provider.js.map +1 -0
- package/out/src/reqlan-inlay-hint-settings.d.ts +10 -0
- package/out/src/reqlan-inlay-hint-settings.js +10 -0
- package/out/src/reqlan-inlay-hint-settings.js.map +1 -0
- package/out/src/reqlan-linker.d.ts +26 -0
- package/out/src/reqlan-linker.js +86 -0
- package/out/src/reqlan-linker.js.map +1 -0
- package/out/src/reqlan-markdown-links.d.ts +28 -0
- package/out/src/reqlan-markdown-links.js +113 -0
- package/out/src/reqlan-markdown-links.js.map +1 -0
- package/out/src/reqlan-module.d.ts +41 -0
- package/out/src/reqlan-module.js +76 -0
- package/out/src/reqlan-module.js.map +1 -0
- package/out/src/reqlan-name-catalog.d.ts +23 -0
- package/out/src/reqlan-name-catalog.js +63 -0
- package/out/src/reqlan-name-catalog.js.map +1 -0
- package/out/src/reqlan-name-provider.d.ts +10 -0
- package/out/src/reqlan-name-provider.js +38 -0
- package/out/src/reqlan-name-provider.js.map +1 -0
- package/out/src/reqlan-namespace-import-links.d.ts +10 -0
- package/out/src/reqlan-namespace-import-links.js +81 -0
- package/out/src/reqlan-namespace-import-links.js.map +1 -0
- package/out/src/reqlan-path-completion.d.ts +50 -0
- package/out/src/reqlan-path-completion.js +304 -0
- package/out/src/reqlan-path-completion.js.map +1 -0
- package/out/src/reqlan-path-references.d.ts +5 -0
- package/out/src/reqlan-path-references.js +124 -0
- package/out/src/reqlan-path-references.js.map +1 -0
- package/out/src/reqlan-path-resolve.d.ts +59 -0
- package/out/src/reqlan-path-resolve.js +173 -0
- package/out/src/reqlan-path-resolve.js.map +1 -0
- package/out/src/reqlan-quoted-strings.d.ts +9 -0
- package/out/src/reqlan-quoted-strings.js +26 -0
- package/out/src/reqlan-quoted-strings.js.map +1 -0
- package/out/src/reqlan-reference-at-position.d.ts +20 -0
- package/out/src/reqlan-reference-at-position.js +89 -0
- package/out/src/reqlan-reference-at-position.js.map +1 -0
- package/out/src/reqlan-references.d.ts +16 -0
- package/out/src/reqlan-references.js +51 -0
- package/out/src/reqlan-references.js.map +1 -0
- package/out/src/reqlan-scope.d.ts +25 -0
- package/out/src/reqlan-scope.js +266 -0
- package/out/src/reqlan-scope.js.map +1 -0
- package/out/src/reqlan-semantic-token-provider.d.ts +8 -0
- package/out/src/reqlan-semantic-token-provider.js +97 -0
- package/out/src/reqlan-semantic-token-provider.js.map +1 -0
- package/out/src/reqlan-token-builder.d.ts +12 -0
- package/out/src/reqlan-token-builder.js +459 -0
- package/out/src/reqlan-token-builder.js.map +1 -0
- package/out/src/reqlan-validator.d.ts +25 -0
- package/out/src/reqlan-validator.js +119 -0
- package/out/src/reqlan-validator.js.map +1 -0
- package/out/src/reqlan-workspace-attribute-catalog.d.ts +6 -0
- package/out/src/reqlan-workspace-attribute-catalog.js +54 -0
- package/out/src/reqlan-workspace-attribute-catalog.js.map +1 -0
- package/out/test/code-actions.test.d.ts +1 -0
- package/out/test/code-actions.test.js +126 -0
- package/out/test/code-actions.test.js.map +1 -0
- package/out/test/comment-in-string.test.d.ts +1 -0
- package/out/test/comment-in-string.test.js +100 -0
- package/out/test/comment-in-string.test.js.map +1 -0
- package/out/test/completion.test.d.ts +1 -0
- package/out/test/completion.test.js +467 -0
- package/out/test/completion.test.js.map +1 -0
- package/out/test/file-path-rewrite.test.d.ts +1 -0
- package/out/test/file-path-rewrite.test.js +64 -0
- package/out/test/file-path-rewrite.test.js.map +1 -0
- package/out/test/ignore-error.test.d.ts +1 -0
- package/out/test/ignore-error.test.js +87 -0
- package/out/test/ignore-error.test.js.map +1 -0
- package/out/test/implicit-import-extension.test.d.ts +1 -0
- package/out/test/implicit-import-extension.test.js +203 -0
- package/out/test/implicit-import-extension.test.js.map +1 -0
- package/out/test/import-edits.test.d.ts +1 -0
- package/out/test/import-edits.test.js +20 -0
- package/out/test/import-edits.test.js.map +1 -0
- package/out/test/inlay-hints.test.d.ts +1 -0
- package/out/test/inlay-hints.test.js +238 -0
- package/out/test/inlay-hints.test.js.map +1 -0
- package/out/test/linking.test.d.ts +1 -0
- package/out/test/linking.test.js +754 -0
- package/out/test/linking.test.js.map +1 -0
- package/out/test/naked-strings.test.d.ts +1 -0
- package/out/test/naked-strings.test.js +50 -0
- package/out/test/naked-strings.test.js.map +1 -0
- package/out/test/parsing.test.d.ts +1 -0
- package/out/test/parsing.test.js +773 -0
- package/out/test/parsing.test.js.map +1 -0
- package/out/test/path-resolve.test.d.ts +1 -0
- package/out/test/path-resolve.test.js +88 -0
- package/out/test/path-resolve.test.js.map +1 -0
- package/out/test/references.test.d.ts +1 -0
- package/out/test/references.test.js +168 -0
- package/out/test/references.test.js.map +1 -0
- package/out/test/rqconfig.test.d.ts +1 -0
- package/out/test/rqconfig.test.js +275 -0
- package/out/test/rqconfig.test.js.map +1 -0
- package/out/test/test-requirement-refs.d.ts +8 -0
- package/out/test/test-requirement-refs.js +35 -0
- package/out/test/test-requirement-refs.js.map +1 -0
- package/out/test/testing.test.d.ts +1 -0
- package/out/test/testing.test.js +23 -0
- package/out/test/testing.test.js.map +1 -0
- package/out/test/validating.test.d.ts +1 -0
- package/out/test/validating.test.js +117 -0
- package/out/test/validating.test.js.map +1 -0
- package/out/tsconfig.tsbuildinfo +1 -0
- package/package.json +54 -0
- package/src/chevrotain.d.ts +8 -0
- package/src/file-path-rewrite.ts +96 -0
- package/src/generated/ast.ts +1481 -0
- package/src/generated/grammar.ts +3074 -0
- package/src/generated/module.ts +38 -0
- package/src/index.ts +34 -0
- package/src/reqlan-attribute-catalog.ts +100 -0
- package/src/reqlan-code-action-provider.ts +385 -0
- package/src/reqlan-code-lens-provider.ts +54 -0
- package/src/reqlan-code-lens-settings.ts +42 -0
- package/src/reqlan-comment-resolver.ts +372 -0
- package/src/reqlan-comment.langium +23 -0
- package/src/reqlan-completion-context.ts +330 -0
- package/src/reqlan-completion-provider.ts +400 -0
- package/src/reqlan-definition-provider.ts +319 -0
- package/src/reqlan-document-highlight-provider.ts +21 -0
- package/src/reqlan-document-link-provider.ts +45 -0
- package/src/reqlan-embedded-file-references.ts +72 -0
- package/src/reqlan-file-link-resolver.ts +485 -0
- package/src/reqlan-file-references.ts +84 -0
- package/src/reqlan-grammar-config.ts +14 -0
- package/src/reqlan-idea-reference-site.ts +74 -0
- package/src/reqlan-idea-summary.ts +162 -0
- package/src/reqlan-ignore-error.ts +50 -0
- package/src/reqlan-import-bindings.ts +87 -0
- package/src/reqlan-import-edits.ts +124 -0
- package/src/reqlan-imports.ts +115 -0
- package/src/reqlan-inbound-reference-inlay-label.ts +194 -0
- package/src/reqlan-inlay-hint-provider.ts +88 -0
- package/src/reqlan-inlay-hint-settings.ts +15 -0
- package/src/reqlan-linker.ts +108 -0
- package/src/reqlan-markdown-links.ts +136 -0
- package/src/reqlan-module.ts +104 -0
- package/src/reqlan-name-catalog.ts +81 -0
- package/src/reqlan-name-provider.ts +56 -0
- package/src/reqlan-namespace-import-links.ts +92 -0
- package/src/reqlan-path-completion.ts +420 -0
- package/src/reqlan-path-references.ts +140 -0
- package/src/reqlan-path-resolve.ts +346 -0
- package/src/reqlan-quoted-strings.ts +30 -0
- package/src/reqlan-reference-at-position.ts +154 -0
- package/src/reqlan-reference-code-lens.ts +323 -0
- package/src/reqlan-reference-search-site.ts +202 -0
- package/src/reqlan-references.ts +76 -0
- package/src/reqlan-scope.ts +312 -0
- package/src/reqlan-semantic-token-provider.ts +113 -0
- package/src/reqlan-token-builder.ts +492 -0
- package/src/reqlan-validator.ts +149 -0
- package/src/reqlan-workspace-attribute-catalog.ts +62 -0
- package/src/reqlan.langium +236 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects where completion was requested in a reqlan document.
|
|
3
|
+
*/
|
|
4
|
+
import type { CstNode, LangiumDocument } from 'langium';
|
|
5
|
+
import { AstUtils, CstUtils, GrammarUtils } from 'langium';
|
|
6
|
+
import type { Position } from 'vscode-languageserver';
|
|
7
|
+
import {
|
|
8
|
+
isAttribute,
|
|
9
|
+
isBracketReference,
|
|
10
|
+
isFileReference,
|
|
11
|
+
isFileSymbolReference,
|
|
12
|
+
isIdea,
|
|
13
|
+
isImport,
|
|
14
|
+
isMarkdownLink,
|
|
15
|
+
isOneLinerIdea,
|
|
16
|
+
isQualifiedReference,
|
|
17
|
+
isWikiLink,
|
|
18
|
+
type Attribute,
|
|
19
|
+
type IdeaDeclaration
|
|
20
|
+
} from './generated/ast.js';
|
|
21
|
+
import {
|
|
22
|
+
isMarkdownLinkLabelPosition,
|
|
23
|
+
linePrefixBeforeMarkdownLinkTarget
|
|
24
|
+
} from './reqlan-markdown-links.js';
|
|
25
|
+
|
|
26
|
+
export type CompletionSite =
|
|
27
|
+
| 'main_description'
|
|
28
|
+
| 'attribute_key'
|
|
29
|
+
| 'attribute_value'
|
|
30
|
+
| 'reference'
|
|
31
|
+
| 'anonymous_import_path'
|
|
32
|
+
| 'default';
|
|
33
|
+
|
|
34
|
+
export interface AttributeKeyContext {
|
|
35
|
+
prefix: string;
|
|
36
|
+
replaceStart: Position;
|
|
37
|
+
replaceEnd: Position;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AttributeValueContext {
|
|
41
|
+
attributeName: string;
|
|
42
|
+
prefix: string;
|
|
43
|
+
replaceStart: Position;
|
|
44
|
+
replaceEnd: Position;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ReferencePrefixContext {
|
|
48
|
+
prefix: string;
|
|
49
|
+
replaceStart: Position;
|
|
50
|
+
replaceEnd: Position;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface AnonymousImportPathContext {
|
|
54
|
+
prefix: string;
|
|
55
|
+
delimiter: '"' | "'";
|
|
56
|
+
replaceStart: Position;
|
|
57
|
+
replaceEnd: Position;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getCompletionSite(document: LangiumDocument, position: Position): CompletionSite {
|
|
61
|
+
if (getAttributeKeyContext(document, position)) {
|
|
62
|
+
return 'attribute_key';
|
|
63
|
+
}
|
|
64
|
+
if (getAttributeValueContext(document, position)) {
|
|
65
|
+
return 'attribute_value';
|
|
66
|
+
}
|
|
67
|
+
if (getAnonymousImportPathContext(document, position)) {
|
|
68
|
+
return 'anonymous_import_path';
|
|
69
|
+
}
|
|
70
|
+
if (getReferencePrefixContext(document, position)) {
|
|
71
|
+
return 'reference';
|
|
72
|
+
}
|
|
73
|
+
if (isInMainDescriptionProse(document, position)) {
|
|
74
|
+
return 'main_description';
|
|
75
|
+
}
|
|
76
|
+
return 'default';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Quoted path inside a bracket reference, e.g. `["@/…` or `['./foo`.
|
|
81
|
+
* Text-based so incomplete/unclosed strings still complete like import paths.
|
|
82
|
+
* rq:["../../../reqlan rq/extension/language-support/features-imports.rq".anonymous_reference_code_completion]
|
|
83
|
+
*/
|
|
84
|
+
export function getAnonymousImportPathContext(
|
|
85
|
+
document: LangiumDocument,
|
|
86
|
+
position: Position
|
|
87
|
+
): AnonymousImportPathContext | undefined {
|
|
88
|
+
if (isMarkdownLinkLabelPosition(document, position) || linePrefixBeforeMarkdownLinkTarget(document, position)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const line = document.textDocument.getText({
|
|
92
|
+
start: { line: position.line, character: 0 },
|
|
93
|
+
end: { line: position.line, character: position.character }
|
|
94
|
+
});
|
|
95
|
+
const match = /(?:^|[^[])\[(["'])([^"']*)$/.exec(line);
|
|
96
|
+
if (!match) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const delimiter = match[1] as '"' | "'";
|
|
100
|
+
const prefix = match[2] ?? '';
|
|
101
|
+
return {
|
|
102
|
+
prefix,
|
|
103
|
+
delimiter,
|
|
104
|
+
replaceStart: { line: position.line, character: position.character - prefix.length },
|
|
105
|
+
replaceEnd: position
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function getAttributeKeyContext(
|
|
110
|
+
document: LangiumDocument,
|
|
111
|
+
position: Position
|
|
112
|
+
): AttributeKeyContext | undefined {
|
|
113
|
+
const line = document.textDocument.getText({
|
|
114
|
+
start: { line: position.line, character: 0 },
|
|
115
|
+
end: { line: position.line, character: position.character }
|
|
116
|
+
});
|
|
117
|
+
const match = line.match(/^\s*@([\w_]*)$/);
|
|
118
|
+
if (!match) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const prefix = match[1] ?? '';
|
|
122
|
+
const atIndex = line.indexOf('@');
|
|
123
|
+
return {
|
|
124
|
+
prefix,
|
|
125
|
+
replaceStart: { line: position.line, character: atIndex + 1 },
|
|
126
|
+
replaceEnd: position
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function getReferencePrefixContext(
|
|
131
|
+
document: LangiumDocument,
|
|
132
|
+
position: Position
|
|
133
|
+
): ReferencePrefixContext | undefined {
|
|
134
|
+
if (isMarkdownLinkLabelPosition(document, position) || linePrefixBeforeMarkdownLinkTarget(document, position)) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const line = document.textDocument.getText({
|
|
138
|
+
start: { line: position.line, character: 0 },
|
|
139
|
+
end: { line: position.line, character: position.character }
|
|
140
|
+
});
|
|
141
|
+
const bracketMatch = line.match(/\[[\w_.]*$/);
|
|
142
|
+
if (bracketMatch) {
|
|
143
|
+
const prefix = bracketMatch[0].slice(1);
|
|
144
|
+
return {
|
|
145
|
+
prefix,
|
|
146
|
+
replaceStart: { line: position.line, character: position.character - prefix.length },
|
|
147
|
+
replaceEnd: position
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const wikiMatch = line.match(/\[\[[\w_.]*$/);
|
|
151
|
+
if (wikiMatch) {
|
|
152
|
+
const prefix = wikiMatch[0].slice(2);
|
|
153
|
+
return {
|
|
154
|
+
prefix,
|
|
155
|
+
replaceStart: { line: position.line, character: position.character - prefix.length },
|
|
156
|
+
replaceEnd: position
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function getAttributeValueContext(
|
|
163
|
+
document: LangiumDocument,
|
|
164
|
+
position: Position
|
|
165
|
+
): AttributeValueContext | undefined {
|
|
166
|
+
const linePrefix = document.textDocument.getText({
|
|
167
|
+
start: { line: position.line, character: 0 },
|
|
168
|
+
end: position
|
|
169
|
+
});
|
|
170
|
+
const inlineMatch = linePrefix.match(/^\s*@([\w_]+)(?:\s*:\s*|\s+)(\S*)$/);
|
|
171
|
+
if (inlineMatch) {
|
|
172
|
+
const attributeName = inlineMatch[1]!;
|
|
173
|
+
const prefix = inlineMatch[2] ?? '';
|
|
174
|
+
const valueStart = linePrefix.length - prefix.length;
|
|
175
|
+
const attribute = findAttributeAtPosition(document, position);
|
|
176
|
+
if (attribute?.value && isProseAttributeValue(attribute)) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
attributeName,
|
|
181
|
+
prefix,
|
|
182
|
+
replaceStart: { line: position.line, character: valueStart },
|
|
183
|
+
replaceEnd: position
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const attribute = findAttributeAtPosition(document, position);
|
|
187
|
+
if (!attribute || !attribute.value || isProseAttributeValue(attribute)) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
const listMatch = linePrefix.match(/^\s+(\S*)$/);
|
|
191
|
+
if (listMatch && attribute.value.$type === 'ListValue') {
|
|
192
|
+
const valueStart = linePrefix.search(/\S/);
|
|
193
|
+
if (valueStart >= 0) {
|
|
194
|
+
return {
|
|
195
|
+
attributeName: attribute.name,
|
|
196
|
+
prefix: listMatch[1] ?? '',
|
|
197
|
+
replaceStart: { line: position.line, character: valueStart },
|
|
198
|
+
replaceEnd: position
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function isInMainDescriptionProse(document: LangiumDocument, position: Position): boolean {
|
|
206
|
+
if (getAnonymousImportPathContext(document, position) || getReferencePrefixContext(document, position)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
const linePrefix = document.textDocument.getText({
|
|
210
|
+
start: { line: position.line, character: 0 },
|
|
211
|
+
end: position
|
|
212
|
+
});
|
|
213
|
+
if (/^\s*@/.test(linePrefix)) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
if (isInsideReferencePartAtPosition(document, position)) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
return findContainingIdea(document, position) !== undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function isImportPathCompletion(contextProperty: string | undefined, container: unknown): boolean {
|
|
223
|
+
return contextProperty === 'path' && isImport(container);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function isFilePathCompletion(contextProperty: string | undefined, container: unknown): boolean {
|
|
227
|
+
return contextProperty === 'file' && (isFileReference(container) || isFileSymbolReference(container));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Innermost idea / one-liner whose range covers `position` (for completion ranking). */
|
|
231
|
+
export function findContainingIdea(
|
|
232
|
+
document: LangiumDocument,
|
|
233
|
+
position: Position
|
|
234
|
+
): IdeaDeclaration | undefined {
|
|
235
|
+
let match: IdeaDeclaration | undefined;
|
|
236
|
+
for (const node of AstUtils.streamAst(document.parseResult.value)) {
|
|
237
|
+
if ((!isIdea(node) && !isOneLinerIdea(node)) || !node.$cstNode?.range) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const range = node.$cstNode.range;
|
|
241
|
+
if (position.line >= range.start.line && position.line <= range.end.line) {
|
|
242
|
+
match = node;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return match;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function findAttributeAtPosition(document: LangiumDocument, position: Position): Attribute | undefined {
|
|
249
|
+
const root = document.parseResult.value.$cstNode;
|
|
250
|
+
if (!root) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
const offset = document.textDocument.offsetAt(position);
|
|
254
|
+
let current: CstNode | undefined = CstUtils.findLeafNodeAtOffset(root, offset);
|
|
255
|
+
while (current) {
|
|
256
|
+
if (isAttribute(current.astNode)) {
|
|
257
|
+
return current.astNode;
|
|
258
|
+
}
|
|
259
|
+
current = current.container;
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function isProseAttributeValue(attribute: Attribute): boolean {
|
|
265
|
+
if (!attribute.value) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
return attribute.value.$type === 'BlockValue';
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isInsideReferencePartAtPosition(document: LangiumDocument, position: Position): boolean {
|
|
272
|
+
const root = document.parseResult.value.$cstNode;
|
|
273
|
+
if (!root) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const offset = document.textDocument.offsetAt(position);
|
|
277
|
+
const leaf = CstUtils.findLeafNodeAtOffset(root, offset);
|
|
278
|
+
return leaf ? isInsideReferencePart(leaf) : false;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function isInsideReferencePart(leaf: CstNode): boolean {
|
|
282
|
+
let current: CstNode | undefined = leaf;
|
|
283
|
+
while (current) {
|
|
284
|
+
if (
|
|
285
|
+
isMarkdownLink(current.astNode)
|
|
286
|
+
|| isBracketReference(current.astNode)
|
|
287
|
+
|| isWikiLink(current.astNode)
|
|
288
|
+
|| isFileReference(current.astNode)
|
|
289
|
+
|| isFileSymbolReference(current.astNode)
|
|
290
|
+
|| isQualifiedReference(current.astNode)
|
|
291
|
+
) {
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
current = current.container;
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function assignmentFeatureAt(document: LangiumDocument, position: Position): string | undefined {
|
|
300
|
+
const root = document.parseResult.value.$cstNode;
|
|
301
|
+
if (!root) {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
const offset = document.textDocument.offsetAt(position);
|
|
305
|
+
let current: CstNode | undefined = CstUtils.findLeafNodeAtOffset(root, offset);
|
|
306
|
+
while (current) {
|
|
307
|
+
const assignment = GrammarUtils.findAssignment(current);
|
|
308
|
+
if (assignment) {
|
|
309
|
+
return assignment.feature;
|
|
310
|
+
}
|
|
311
|
+
current = current.container;
|
|
312
|
+
}
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function containerAstNodeAt(document: LangiumDocument, position: Position): unknown {
|
|
317
|
+
const root = document.parseResult.value.$cstNode;
|
|
318
|
+
if (!root) {
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
const offset = document.textDocument.offsetAt(position);
|
|
322
|
+
let current: CstNode | undefined = CstUtils.findLeafNodeAtOffset(root, offset);
|
|
323
|
+
while (current) {
|
|
324
|
+
if (current.astNode && current.astNode !== document.parseResult.value) {
|
|
325
|
+
return current.astNode;
|
|
326
|
+
}
|
|
327
|
+
current = current.container;
|
|
328
|
+
}
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|