@macroforge/svelte-language-server 0.1.3
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 +331 -0
- package/bin/server.js +5 -0
- package/dist/src/importPackage.d.ts +16 -0
- package/dist/src/importPackage.js +76 -0
- package/dist/src/importPackage.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +23 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/DiagnosticsManager.d.ts +20 -0
- package/dist/src/lib/DiagnosticsManager.js +71 -0
- package/dist/src/lib/DiagnosticsManager.js.map +1 -0
- package/dist/src/lib/FallbackWatcher.d.ts +15 -0
- package/dist/src/lib/FallbackWatcher.js +66 -0
- package/dist/src/lib/FallbackWatcher.js.map +1 -0
- package/dist/src/lib/documentHighlight/wordHighlight.d.ts +3 -0
- package/dist/src/lib/documentHighlight/wordHighlight.js +62 -0
- package/dist/src/lib/documentHighlight/wordHighlight.js.map +1 -0
- package/dist/src/lib/documents/Document.d.ts +63 -0
- package/dist/src/lib/documents/Document.js +138 -0
- package/dist/src/lib/documents/Document.js.map +1 -0
- package/dist/src/lib/documents/DocumentBase.d.ts +65 -0
- package/dist/src/lib/documents/DocumentBase.js +69 -0
- package/dist/src/lib/documents/DocumentBase.js.map +1 -0
- package/dist/src/lib/documents/DocumentManager.d.ts +28 -0
- package/dist/src/lib/documents/DocumentManager.js +122 -0
- package/dist/src/lib/documents/DocumentManager.js.map +1 -0
- package/dist/src/lib/documents/DocumentMapper.d.ts +88 -0
- package/dist/src/lib/documents/DocumentMapper.js +258 -0
- package/dist/src/lib/documents/DocumentMapper.js.map +1 -0
- package/dist/src/lib/documents/configLoader.d.ts +80 -0
- package/dist/src/lib/documents/configLoader.js +265 -0
- package/dist/src/lib/documents/configLoader.js.map +1 -0
- package/dist/src/lib/documents/fileCollection.d.ts +41 -0
- package/dist/src/lib/documents/fileCollection.js +87 -0
- package/dist/src/lib/documents/fileCollection.js.map +1 -0
- package/dist/src/lib/documents/index.d.ts +5 -0
- package/dist/src/lib/documents/index.js +22 -0
- package/dist/src/lib/documents/index.js.map +1 -0
- package/dist/src/lib/documents/parseHtml.d.ts +13 -0
- package/dist/src/lib/documents/parseHtml.js +160 -0
- package/dist/src/lib/documents/parseHtml.js.map +1 -0
- package/dist/src/lib/documents/utils.d.ts +105 -0
- package/dist/src/lib/documents/utils.js +410 -0
- package/dist/src/lib/documents/utils.js.map +1 -0
- package/dist/src/lib/foldingRange/indentFolding.d.ts +26 -0
- package/dist/src/lib/foldingRange/indentFolding.js +142 -0
- package/dist/src/lib/foldingRange/indentFolding.js.map +1 -0
- package/dist/src/lib/semanticToken/semanticTokenLegend.d.ts +33 -0
- package/dist/src/lib/semanticToken/semanticTokenLegend.js +37 -0
- package/dist/src/lib/semanticToken/semanticTokenLegend.js.map +1 -0
- package/dist/src/logger.d.ts +9 -0
- package/dist/src/logger.js +28 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/ls-config.d.ts +326 -0
- package/dist/src/ls-config.js +386 -0
- package/dist/src/ls-config.js.map +1 -0
- package/dist/src/plugins/PluginHost.d.ts +68 -0
- package/dist/src/plugins/PluginHost.js +447 -0
- package/dist/src/plugins/PluginHost.js.map +1 -0
- package/dist/src/plugins/css/CSSDocument.d.ts +46 -0
- package/dist/src/plugins/css/CSSDocument.js +78 -0
- package/dist/src/plugins/css/CSSDocument.js.map +1 -0
- package/dist/src/plugins/css/CSSPlugin.d.ts +35 -0
- package/dist/src/plugins/css/CSSPlugin.js +407 -0
- package/dist/src/plugins/css/CSSPlugin.js.map +1 -0
- package/dist/src/plugins/css/FileSystemProvider.d.ts +10 -0
- package/dist/src/plugins/css/FileSystemProvider.js +75 -0
- package/dist/src/plugins/css/FileSystemProvider.js.map +1 -0
- package/dist/src/plugins/css/StyleAttributeDocument.d.ts +41 -0
- package/dist/src/plugins/css/StyleAttributeDocument.js +65 -0
- package/dist/src/plugins/css/StyleAttributeDocument.js.map +1 -0
- package/dist/src/plugins/css/features/getIdClassCompletion.d.ts +19 -0
- package/dist/src/plugins/css/features/getIdClassCompletion.js +56 -0
- package/dist/src/plugins/css/features/getIdClassCompletion.js.map +1 -0
- package/dist/src/plugins/css/features/svelte-selectors.d.ts +2 -0
- package/dist/src/plugins/css/features/svelte-selectors.js +18 -0
- package/dist/src/plugins/css/features/svelte-selectors.js.map +1 -0
- package/dist/src/plugins/css/global-vars.d.ts +16 -0
- package/dist/src/plugins/css/global-vars.js +82 -0
- package/dist/src/plugins/css/global-vars.js.map +1 -0
- package/dist/src/plugins/css/service.d.ts +5 -0
- package/dist/src/plugins/css/service.js +66 -0
- package/dist/src/plugins/css/service.js.map +1 -0
- package/dist/src/plugins/documentContext.d.ts +3 -0
- package/dist/src/plugins/documentContext.js +36 -0
- package/dist/src/plugins/documentContext.js.map +1 -0
- package/dist/src/plugins/html/HTMLPlugin.d.ts +36 -0
- package/dist/src/plugins/html/HTMLPlugin.js +363 -0
- package/dist/src/plugins/html/HTMLPlugin.js.map +1 -0
- package/dist/src/plugins/html/dataProvider.d.ts +1 -0
- package/dist/src/plugins/html/dataProvider.js +481 -0
- package/dist/src/plugins/html/dataProvider.js.map +1 -0
- package/dist/src/plugins/index.d.ts +7 -0
- package/dist/src/plugins/index.js +24 -0
- package/dist/src/plugins/index.js.map +1 -0
- package/dist/src/plugins/interfaces.d.ts +132 -0
- package/dist/src/plugins/interfaces.js +3 -0
- package/dist/src/plugins/interfaces.js.map +1 -0
- package/dist/src/plugins/svelte/SvelteDocument.d.ts +98 -0
- package/dist/src/plugins/svelte/SvelteDocument.js +318 -0
- package/dist/src/plugins/svelte/SvelteDocument.js.map +1 -0
- package/dist/src/plugins/svelte/SveltePlugin.d.ts +24 -0
- package/dist/src/plugins/svelte/SveltePlugin.js +306 -0
- package/dist/src/plugins/svelte/SveltePlugin.js.map +1 -0
- package/dist/src/plugins/svelte/features/SvelteTags.d.ts +28 -0
- package/dist/src/plugins/svelte/features/SvelteTags.js +136 -0
- package/dist/src/plugins/svelte/features/SvelteTags.js.map +1 -0
- package/dist/src/plugins/svelte/features/getCodeActions/getQuickfixes.d.ts +11 -0
- package/dist/src/plugins/svelte/features/getCodeActions/getQuickfixes.js +140 -0
- package/dist/src/plugins/svelte/features/getCodeActions/getQuickfixes.js.map +1 -0
- package/dist/src/plugins/svelte/features/getCodeActions/getRefactorings.d.ts +9 -0
- package/dist/src/plugins/svelte/features/getCodeActions/getRefactorings.js +140 -0
- package/dist/src/plugins/svelte/features/getCodeActions/getRefactorings.js.map +1 -0
- package/dist/src/plugins/svelte/features/getCodeActions/index.d.ts +4 -0
- package/dist/src/plugins/svelte/features/getCodeActions/index.js +19 -0
- package/dist/src/plugins/svelte/features/getCodeActions/index.js.map +1 -0
- package/dist/src/plugins/svelte/features/getCompletions.d.ts +4 -0
- package/dist/src/plugins/svelte/features/getCompletions.js +184 -0
- package/dist/src/plugins/svelte/features/getCompletions.js.map +1 -0
- package/dist/src/plugins/svelte/features/getDiagnostics.d.ts +9 -0
- package/dist/src/plugins/svelte/features/getDiagnostics.js +284 -0
- package/dist/src/plugins/svelte/features/getDiagnostics.js.map +1 -0
- package/dist/src/plugins/svelte/features/getHoverInfo.d.ts +7 -0
- package/dist/src/plugins/svelte/features/getHoverInfo.js +93 -0
- package/dist/src/plugins/svelte/features/getHoverInfo.js.map +1 -0
- package/dist/src/plugins/svelte/features/getModifierData.d.ts +7 -0
- package/dist/src/plugins/svelte/features/getModifierData.js +56 -0
- package/dist/src/plugins/svelte/features/getModifierData.js.map +1 -0
- package/dist/src/plugins/svelte/features/getSelectionRanges.d.ts +3 -0
- package/dist/src/plugins/svelte/features/getSelectionRanges.js +46 -0
- package/dist/src/plugins/svelte/features/getSelectionRanges.js.map +1 -0
- package/dist/src/plugins/svelte/features/utils.d.ts +5 -0
- package/dist/src/plugins/svelte/features/utils.js +18 -0
- package/dist/src/plugins/svelte/features/utils.js.map +1 -0
- package/dist/src/plugins/typescript/ComponentInfoProvider.d.ts +27 -0
- package/dist/src/plugins/typescript/ComponentInfoProvider.js +116 -0
- package/dist/src/plugins/typescript/ComponentInfoProvider.js.map +1 -0
- package/dist/src/plugins/typescript/DocumentMapper.d.ts +10 -0
- package/dist/src/plugins/typescript/DocumentMapper.js +25 -0
- package/dist/src/plugins/typescript/DocumentMapper.js.map +1 -0
- package/dist/src/plugins/typescript/DocumentSnapshot.d.ts +173 -0
- package/dist/src/plugins/typescript/DocumentSnapshot.js +623 -0
- package/dist/src/plugins/typescript/DocumentSnapshot.js.map +1 -0
- package/dist/src/plugins/typescript/LSAndTSDocResolver.d.ts +100 -0
- package/dist/src/plugins/typescript/LSAndTSDocResolver.js +301 -0
- package/dist/src/plugins/typescript/LSAndTSDocResolver.js.map +1 -0
- package/dist/src/plugins/typescript/SnapshotManager.d.ts +59 -0
- package/dist/src/plugins/typescript/SnapshotManager.js +238 -0
- package/dist/src/plugins/typescript/SnapshotManager.js.map +1 -0
- package/dist/src/plugins/typescript/TypeScriptPlugin.d.ts +65 -0
- package/dist/src/plugins/typescript/TypeScriptPlugin.js +332 -0
- package/dist/src/plugins/typescript/TypeScriptPlugin.js.map +1 -0
- package/dist/src/plugins/typescript/features/CallHierarchyProvider.d.ts +24 -0
- package/dist/src/plugins/typescript/features/CallHierarchyProvider.js +325 -0
- package/dist/src/plugins/typescript/features/CallHierarchyProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/CodeActionsProvider.d.ts +72 -0
- package/dist/src/plugins/typescript/features/CodeActionsProvider.js +1030 -0
- package/dist/src/plugins/typescript/features/CodeActionsProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/CodeLensProvider.d.ts +28 -0
- package/dist/src/plugins/typescript/features/CodeLensProvider.js +205 -0
- package/dist/src/plugins/typescript/features/CodeLensProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/CompletionProvider.d.ts +57 -0
- package/dist/src/plugins/typescript/features/CompletionProvider.js +791 -0
- package/dist/src/plugins/typescript/features/CompletionProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/DiagnosticsProvider.d.ts +36 -0
- package/dist/src/plugins/typescript/features/DiagnosticsProvider.js +497 -0
- package/dist/src/plugins/typescript/features/DiagnosticsProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/DocumentHighlightProvider.d.ts +17 -0
- package/dist/src/plugins/typescript/features/DocumentHighlightProvider.js +211 -0
- package/dist/src/plugins/typescript/features/DocumentHighlightProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/FindComponentReferencesProvider.d.ts +9 -0
- package/dist/src/plugins/typescript/features/FindComponentReferencesProvider.js +66 -0
- package/dist/src/plugins/typescript/features/FindComponentReferencesProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/FindFileReferencesProvider.d.ts +9 -0
- package/dist/src/plugins/typescript/features/FindFileReferencesProvider.js +38 -0
- package/dist/src/plugins/typescript/features/FindFileReferencesProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/FindReferencesProvider.d.ts +20 -0
- package/dist/src/plugins/typescript/features/FindReferencesProvider.js +149 -0
- package/dist/src/plugins/typescript/features/FindReferencesProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/FoldingRangeProvider.d.ts +28 -0
- package/dist/src/plugins/typescript/features/FoldingRangeProvider.js +247 -0
- package/dist/src/plugins/typescript/features/FoldingRangeProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/HoverProvider.d.ts +11 -0
- package/dist/src/plugins/typescript/features/HoverProvider.js +75 -0
- package/dist/src/plugins/typescript/features/HoverProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/ImplementationProvider.d.ts +9 -0
- package/dist/src/plugins/typescript/features/ImplementationProvider.js +47 -0
- package/dist/src/plugins/typescript/features/ImplementationProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/InlayHintProvider.d.ts +22 -0
- package/dist/src/plugins/typescript/features/InlayHintProvider.js +225 -0
- package/dist/src/plugins/typescript/features/InlayHintProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/RenameProvider.d.ts +53 -0
- package/dist/src/plugins/typescript/features/RenameProvider.js +423 -0
- package/dist/src/plugins/typescript/features/RenameProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/SelectionRangeProvider.d.ts +18 -0
- package/dist/src/plugins/typescript/features/SelectionRangeProvider.js +62 -0
- package/dist/src/plugins/typescript/features/SelectionRangeProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/SemanticTokensProvider.d.ts +15 -0
- package/dist/src/plugins/typescript/features/SemanticTokensProvider.js +116 -0
- package/dist/src/plugins/typescript/features/SemanticTokensProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/SignatureHelpProvider.d.ts +22 -0
- package/dist/src/plugins/typescript/features/SignatureHelpProvider.js +110 -0
- package/dist/src/plugins/typescript/features/SignatureHelpProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/TypeDefinitionProvider.d.ts +9 -0
- package/dist/src/plugins/typescript/features/TypeDefinitionProvider.js +35 -0
- package/dist/src/plugins/typescript/features/TypeDefinitionProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/UpdateImportsProvider.d.ts +11 -0
- package/dist/src/plugins/typescript/features/UpdateImportsProvider.js +109 -0
- package/dist/src/plugins/typescript/features/UpdateImportsProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/WorkspaceSymbolProvider.d.ts +25 -0
- package/dist/src/plugins/typescript/features/WorkspaceSymbolProvider.js +176 -0
- package/dist/src/plugins/typescript/features/WorkspaceSymbolProvider.js.map +1 -0
- package/dist/src/plugins/typescript/features/getDirectiveCommentCompletions.d.ts +13 -0
- package/dist/src/plugins/typescript/features/getDirectiveCommentCompletions.js +58 -0
- package/dist/src/plugins/typescript/features/getDirectiveCommentCompletions.js.map +1 -0
- package/dist/src/plugins/typescript/features/getJsDocTemplateCompletion.d.ts +4 -0
- package/dist/src/plugins/typescript/features/getJsDocTemplateCompletion.js +57 -0
- package/dist/src/plugins/typescript/features/getJsDocTemplateCompletion.js.map +1 -0
- package/dist/src/plugins/typescript/features/utils.d.ts +81 -0
- package/dist/src/plugins/typescript/features/utils.js +331 -0
- package/dist/src/plugins/typescript/features/utils.js.map +1 -0
- package/dist/src/plugins/typescript/macroforgeAugmenter.d.ts +23 -0
- package/dist/src/plugins/typescript/macroforgeAugmenter.js +41 -0
- package/dist/src/plugins/typescript/macroforgeAugmenter.js.map +1 -0
- package/dist/src/plugins/typescript/module-loader.d.ts +28 -0
- package/dist/src/plugins/typescript/module-loader.js +254 -0
- package/dist/src/plugins/typescript/module-loader.js.map +1 -0
- package/dist/src/plugins/typescript/previewer.d.ts +7 -0
- package/dist/src/plugins/typescript/previewer.js +120 -0
- package/dist/src/plugins/typescript/previewer.js.map +1 -0
- package/dist/src/plugins/typescript/service.d.ts +105 -0
- package/dist/src/plugins/typescript/service.js +1073 -0
- package/dist/src/plugins/typescript/service.js.map +1 -0
- package/dist/src/plugins/typescript/serviceCache.d.ts +90 -0
- package/dist/src/plugins/typescript/serviceCache.js +50 -0
- package/dist/src/plugins/typescript/serviceCache.js.map +1 -0
- package/dist/src/plugins/typescript/svelte-ast-utils.d.ts +77 -0
- package/dist/src/plugins/typescript/svelte-ast-utils.js +100 -0
- package/dist/src/plugins/typescript/svelte-ast-utils.js.map +1 -0
- package/dist/src/plugins/typescript/svelte-sys.d.ts +9 -0
- package/dist/src/plugins/typescript/svelte-sys.js +79 -0
- package/dist/src/plugins/typescript/svelte-sys.js.map +1 -0
- package/dist/src/plugins/typescript/utils.d.ts +48 -0
- package/dist/src/plugins/typescript/utils.js +334 -0
- package/dist/src/plugins/typescript/utils.js.map +1 -0
- package/dist/src/server.d.ts +19 -0
- package/dist/src/server.js +434 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/svelte-check.d.ts +65 -0
- package/dist/src/svelte-check.js +288 -0
- package/dist/src/svelte-check.js.map +1 -0
- package/dist/src/utils.d.ts +111 -0
- package/dist/src/utils.js +337 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wordHighlightForTag = wordHighlightForTag;
|
|
4
|
+
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
5
|
+
function wordHighlightForTag(document, position, tag, wordPattern) {
|
|
6
|
+
if (!tag || tag.start === tag.end) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const offset = document.offsetAt(position);
|
|
10
|
+
const text = document.getText();
|
|
11
|
+
if (offset < tag.start ||
|
|
12
|
+
offset > tag.end ||
|
|
13
|
+
// empty before and after the cursor
|
|
14
|
+
!text.slice(offset - 1, offset + 1).trim()) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const word = wordAt(document, position, wordPattern);
|
|
18
|
+
if (!word) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const searching = document.getText().slice(tag.start, tag.end);
|
|
22
|
+
const highlights = [];
|
|
23
|
+
let index = 0;
|
|
24
|
+
while (index < searching.length) {
|
|
25
|
+
index = searching.indexOf(word, index);
|
|
26
|
+
if (index === -1) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
const start = tag.start + index;
|
|
30
|
+
highlights.push({
|
|
31
|
+
range: {
|
|
32
|
+
start: document.positionAt(start),
|
|
33
|
+
end: document.positionAt(start + word.length)
|
|
34
|
+
},
|
|
35
|
+
kind: vscode_languageserver_types_1.DocumentHighlightKind.Text
|
|
36
|
+
});
|
|
37
|
+
index += word.length;
|
|
38
|
+
}
|
|
39
|
+
return highlights;
|
|
40
|
+
}
|
|
41
|
+
function wordAt(document, position, wordPattern) {
|
|
42
|
+
const line = document
|
|
43
|
+
.getText(vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(position.line, 0), vscode_languageserver_types_1.Position.create(position.line + 1, 0)))
|
|
44
|
+
.trimEnd();
|
|
45
|
+
wordPattern.lastIndex = 0;
|
|
46
|
+
let start;
|
|
47
|
+
let end;
|
|
48
|
+
const matchEnd = Math.min(position.character, line.length);
|
|
49
|
+
while (wordPattern.lastIndex < matchEnd) {
|
|
50
|
+
const match = wordPattern.exec(line);
|
|
51
|
+
if (!match) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
start = match.index;
|
|
55
|
+
end = match.index + match[0].length;
|
|
56
|
+
}
|
|
57
|
+
if (start === undefined || end === undefined || end < position.character) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return line.slice(start, end);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=wordHighlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wordHighlight.js","sourceRoot":"","sources":["../../../../src/lib/documentHighlight/wordHighlight.ts"],"names":[],"mappings":";;AAQA,kDAmDC;AA3DD,6EAKqC;AAGrC,SAAgB,mBAAmB,CAC/B,QAAkB,EAClB,QAAkB,EAClB,GAA0B,EAC1B,WAAmB;IAEnB,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE3C,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChC,IACI,MAAM,GAAG,GAAG,CAAC,KAAK;QAClB,MAAM,GAAG,GAAG,CAAC,GAAG;QAChB,oCAAoC;QACpC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAC5C,CAAC;QACC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;IACrD,IAAI,CAAC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,GAAuB,CAAC;IAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3D,OAAO,WAAW,CAAC,SAAS,GAAG,QAAQ,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,MAAM;QACV,CAAC;QAED,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,GAAG,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACxC,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;QACvE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { WritableDocument } from './DocumentBase';
|
|
2
|
+
import { TagInformation } from './utils';
|
|
3
|
+
import { SvelteConfig } from './configLoader';
|
|
4
|
+
import { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
+
import { Range } from 'vscode-languageserver';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a text document contains a svelte component.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Document extends WritableDocument {
|
|
10
|
+
url: string;
|
|
11
|
+
content: string;
|
|
12
|
+
languageId: string;
|
|
13
|
+
scriptInfo: TagInformation | null;
|
|
14
|
+
moduleScriptInfo: TagInformation | null;
|
|
15
|
+
styleInfo: TagInformation | null;
|
|
16
|
+
templateInfo: TagInformation | null;
|
|
17
|
+
configPromise: Promise<SvelteConfig | undefined>;
|
|
18
|
+
config?: SvelteConfig;
|
|
19
|
+
html: HTMLDocument;
|
|
20
|
+
openedByClient: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Compute and cache directly because of performance reasons
|
|
23
|
+
* and it will be called anyway.
|
|
24
|
+
*/
|
|
25
|
+
private path;
|
|
26
|
+
private _compiler;
|
|
27
|
+
get compiler(): typeof import("svelte/compiler");
|
|
28
|
+
private svelteVersion;
|
|
29
|
+
get isSvelte5(): boolean;
|
|
30
|
+
constructor(url: string, content: string);
|
|
31
|
+
private getCompiler;
|
|
32
|
+
private updateDocInfo;
|
|
33
|
+
getSvelteVersion(): [number, number];
|
|
34
|
+
/**
|
|
35
|
+
* Get text content
|
|
36
|
+
*/
|
|
37
|
+
getText(range?: Range): string;
|
|
38
|
+
/**
|
|
39
|
+
* Set text content and increase the document version
|
|
40
|
+
*/
|
|
41
|
+
setText(text: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the file path if the url scheme is file
|
|
44
|
+
*/
|
|
45
|
+
getFilePath(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Get URL file path.
|
|
48
|
+
*/
|
|
49
|
+
getURL(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the language associated to script, style or template.
|
|
52
|
+
* Returns an empty string if there's nothing set.
|
|
53
|
+
*/
|
|
54
|
+
getLanguageAttribute(tag: 'script' | 'style' | 'template'): string;
|
|
55
|
+
/**
|
|
56
|
+
* Returns true if there's `lang="X"` on script or style or template.
|
|
57
|
+
*/
|
|
58
|
+
hasLanguageAttribute(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated This no longer exists in svelte-preprocess v5, we leave it in in case someone is using this with v4
|
|
61
|
+
*/
|
|
62
|
+
private addDefaultLanguage;
|
|
63
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const DocumentBase_1 = require("./DocumentBase");
|
|
6
|
+
const utils_2 = require("./utils");
|
|
7
|
+
const parseHtml_1 = require("./parseHtml");
|
|
8
|
+
const configLoader_1 = require("./configLoader");
|
|
9
|
+
const importPackage_1 = require("../../importPackage");
|
|
10
|
+
/**
|
|
11
|
+
* Represents a text document contains a svelte component.
|
|
12
|
+
*/
|
|
13
|
+
class Document extends DocumentBase_1.WritableDocument {
|
|
14
|
+
get compiler() {
|
|
15
|
+
return this.getCompiler();
|
|
16
|
+
}
|
|
17
|
+
get isSvelte5() {
|
|
18
|
+
return this.getSvelteVersion()[0] > 4;
|
|
19
|
+
}
|
|
20
|
+
constructor(url, content) {
|
|
21
|
+
super();
|
|
22
|
+
this.url = url;
|
|
23
|
+
this.content = content;
|
|
24
|
+
this.languageId = 'svelte';
|
|
25
|
+
this.scriptInfo = null;
|
|
26
|
+
this.moduleScriptInfo = null;
|
|
27
|
+
this.styleInfo = null;
|
|
28
|
+
this.templateInfo = null;
|
|
29
|
+
this.openedByClient = false;
|
|
30
|
+
/**
|
|
31
|
+
* Compute and cache directly because of performance reasons
|
|
32
|
+
* and it will be called anyway.
|
|
33
|
+
*/
|
|
34
|
+
this.path = (0, utils_1.urlToPath)(this.url);
|
|
35
|
+
this.configPromise = configLoader_1.configLoader.awaitConfig(this.getFilePath() || '');
|
|
36
|
+
this.updateDocInfo();
|
|
37
|
+
}
|
|
38
|
+
getCompiler() {
|
|
39
|
+
if (!this._compiler) {
|
|
40
|
+
this._compiler = (0, importPackage_1.importSvelte)(this.getFilePath() || '');
|
|
41
|
+
}
|
|
42
|
+
return this._compiler;
|
|
43
|
+
}
|
|
44
|
+
updateDocInfo() {
|
|
45
|
+
this.html = (0, parseHtml_1.parseHtml)(this.content);
|
|
46
|
+
const update = (config) => {
|
|
47
|
+
const scriptTags = (0, utils_2.extractScriptTags)(this.content, this.html);
|
|
48
|
+
this.config = config;
|
|
49
|
+
this.scriptInfo = this.addDefaultLanguage(config, scriptTags?.script || null, 'script');
|
|
50
|
+
this.moduleScriptInfo = this.addDefaultLanguage(config, scriptTags?.moduleScript || null, 'script');
|
|
51
|
+
this.styleInfo = this.addDefaultLanguage(config, (0, utils_2.extractStyleTag)(this.content, this.html), 'style');
|
|
52
|
+
this.templateInfo = this.addDefaultLanguage(config, (0, utils_2.extractTemplateTag)(this.content, this.html), 'markup');
|
|
53
|
+
};
|
|
54
|
+
const config = configLoader_1.configLoader.getConfig(this.getFilePath() || '');
|
|
55
|
+
if (config && !config.loadConfigError) {
|
|
56
|
+
update(config);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
update(undefined);
|
|
60
|
+
this.configPromise.then((c) => update(c));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getSvelteVersion() {
|
|
64
|
+
if (!this.svelteVersion) {
|
|
65
|
+
const [major, minor] = this.compiler.VERSION.split('.');
|
|
66
|
+
this.svelteVersion = [Number(major), Number(minor)];
|
|
67
|
+
}
|
|
68
|
+
return this.svelteVersion;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get text content
|
|
72
|
+
*/
|
|
73
|
+
getText(range) {
|
|
74
|
+
if (range) {
|
|
75
|
+
return this.content.substring(this.offsetAt(range.start), this.offsetAt(range.end));
|
|
76
|
+
}
|
|
77
|
+
return this.content;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set text content and increase the document version
|
|
81
|
+
*/
|
|
82
|
+
setText(text) {
|
|
83
|
+
this.content = text;
|
|
84
|
+
this.version++;
|
|
85
|
+
this.lineOffsets = undefined;
|
|
86
|
+
this.updateDocInfo();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the file path if the url scheme is file
|
|
90
|
+
*/
|
|
91
|
+
getFilePath() {
|
|
92
|
+
return this.path;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get URL file path.
|
|
96
|
+
*/
|
|
97
|
+
getURL() {
|
|
98
|
+
return this.url;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the language associated to script, style or template.
|
|
102
|
+
* Returns an empty string if there's nothing set.
|
|
103
|
+
*/
|
|
104
|
+
getLanguageAttribute(tag) {
|
|
105
|
+
const attrs = (tag === 'style'
|
|
106
|
+
? this.styleInfo?.attributes
|
|
107
|
+
: tag === 'script'
|
|
108
|
+
? this.scriptInfo?.attributes || this.moduleScriptInfo?.attributes
|
|
109
|
+
: this.templateInfo?.attributes) || {};
|
|
110
|
+
const lang = attrs.lang || attrs.type || '';
|
|
111
|
+
return lang.replace(/^text\//, '');
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns true if there's `lang="X"` on script or style or template.
|
|
115
|
+
*/
|
|
116
|
+
hasLanguageAttribute() {
|
|
117
|
+
return (!!this.getLanguageAttribute('script') ||
|
|
118
|
+
!!this.getLanguageAttribute('style') ||
|
|
119
|
+
!!this.getLanguageAttribute('template'));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated This no longer exists in svelte-preprocess v5, we leave it in in case someone is using this with v4
|
|
123
|
+
*/
|
|
124
|
+
addDefaultLanguage(config, tagInfo, tag) {
|
|
125
|
+
if (!tagInfo || !config) {
|
|
126
|
+
return tagInfo;
|
|
127
|
+
}
|
|
128
|
+
const defaultLang = Array.isArray(config.preprocess)
|
|
129
|
+
? config.preprocess.find((group) => group.defaultLanguages?.[tag])?.defaultLanguages?.[tag]
|
|
130
|
+
: config.preprocess?.defaultLanguages?.[tag];
|
|
131
|
+
if (!tagInfo.attributes.lang && !tagInfo.attributes.type && defaultLang) {
|
|
132
|
+
tagInfo.attributes.lang = defaultLang;
|
|
133
|
+
}
|
|
134
|
+
return tagInfo;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.Document = Document;
|
|
138
|
+
//# sourceMappingURL=Document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Document.js","sourceRoot":"","sources":["../../../../src/lib/documents/Document.ts"],"names":[],"mappings":";;;AAAA,uC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,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,oBAAoB;QAChB,OAAO,CACH,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC;YACrC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;YACpC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAC1C,CAAC;IACN,CAAC;IAED;;OAEG;IACK,kBAAkB,CACtB,MAAgC,EAChC,OAA8B,EAC9B,GAAkC;QAElC,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,OAAO,CAAC;QACnB,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;YAChD,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAChF,GAAG,CACN;YACH,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,CAAC;QAEjD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,WAAW,EAAE,CAAC;YACtE,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,WAAW,CAAC;QAC1C,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAtKD,4BAsKC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Position, Range, TextDocument } from 'vscode-languageserver';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a textual document.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class ReadableDocument implements TextDocument {
|
|
6
|
+
/**
|
|
7
|
+
* Get the text content of the document
|
|
8
|
+
*/
|
|
9
|
+
abstract getText(range?: Range): string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the url of the document
|
|
12
|
+
*/
|
|
13
|
+
abstract getURL(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the file path if the url scheme is file
|
|
16
|
+
*/
|
|
17
|
+
abstract getFilePath(): string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Current version of the document.
|
|
20
|
+
*/
|
|
21
|
+
version: number;
|
|
22
|
+
/**
|
|
23
|
+
* Should be cleared when there's an update to the text
|
|
24
|
+
*/
|
|
25
|
+
protected lineOffsets?: number[];
|
|
26
|
+
/**
|
|
27
|
+
* Get the length of the document's content
|
|
28
|
+
*/
|
|
29
|
+
getTextLength(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Get the line and character based on the offset
|
|
32
|
+
* @param offset The index of the position
|
|
33
|
+
*/
|
|
34
|
+
positionAt(offset: number): Position;
|
|
35
|
+
/**
|
|
36
|
+
* Get the index of the line and character position
|
|
37
|
+
* @param position Line and character position
|
|
38
|
+
*/
|
|
39
|
+
offsetAt(position: Position): number;
|
|
40
|
+
private getLineOffsets;
|
|
41
|
+
/**
|
|
42
|
+
* Implements TextDocument
|
|
43
|
+
*/
|
|
44
|
+
get uri(): string;
|
|
45
|
+
get lineCount(): number;
|
|
46
|
+
abstract languageId: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Represents a textual document that can be manipulated.
|
|
50
|
+
*/
|
|
51
|
+
export declare abstract class WritableDocument extends ReadableDocument {
|
|
52
|
+
/**
|
|
53
|
+
* Set the text content of the document.
|
|
54
|
+
* Implementers should set `lineOffsets` to `undefined` here.
|
|
55
|
+
* @param text The new text content
|
|
56
|
+
*/
|
|
57
|
+
abstract setText(text: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Update the text between two positions.
|
|
60
|
+
* @param text The new text slice
|
|
61
|
+
* @param start Start offset of the new text
|
|
62
|
+
* @param end End offset of the new text
|
|
63
|
+
*/
|
|
64
|
+
update(text: string, start: number, end: number): void;
|
|
65
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WritableDocument = exports.ReadableDocument = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a textual document.
|
|
7
|
+
*/
|
|
8
|
+
class ReadableDocument {
|
|
9
|
+
constructor() {
|
|
10
|
+
/**
|
|
11
|
+
* Current version of the document.
|
|
12
|
+
*/
|
|
13
|
+
this.version = 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the length of the document's content
|
|
17
|
+
*/
|
|
18
|
+
getTextLength() {
|
|
19
|
+
return this.getText().length;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the line and character based on the offset
|
|
23
|
+
* @param offset The index of the position
|
|
24
|
+
*/
|
|
25
|
+
positionAt(offset) {
|
|
26
|
+
return (0, utils_1.positionAt)(offset, this.getText(), this.getLineOffsets());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the index of the line and character position
|
|
30
|
+
* @param position Line and character position
|
|
31
|
+
*/
|
|
32
|
+
offsetAt(position) {
|
|
33
|
+
return (0, utils_1.offsetAt)(position, this.getText(), this.getLineOffsets());
|
|
34
|
+
}
|
|
35
|
+
getLineOffsets() {
|
|
36
|
+
if (!this.lineOffsets) {
|
|
37
|
+
this.lineOffsets = (0, utils_1.getLineOffsets)(this.getText());
|
|
38
|
+
}
|
|
39
|
+
return this.lineOffsets;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Implements TextDocument
|
|
43
|
+
*/
|
|
44
|
+
get uri() {
|
|
45
|
+
return this.getURL();
|
|
46
|
+
}
|
|
47
|
+
get lineCount() {
|
|
48
|
+
return this.getText().split(/\r?\n/).length;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ReadableDocument = ReadableDocument;
|
|
52
|
+
/**
|
|
53
|
+
* Represents a textual document that can be manipulated.
|
|
54
|
+
*/
|
|
55
|
+
class WritableDocument extends ReadableDocument {
|
|
56
|
+
/**
|
|
57
|
+
* Update the text between two positions.
|
|
58
|
+
* @param text The new text slice
|
|
59
|
+
* @param start Start offset of the new text
|
|
60
|
+
* @param end End offset of the new text
|
|
61
|
+
*/
|
|
62
|
+
update(text, start, end) {
|
|
63
|
+
this.lineOffsets = undefined;
|
|
64
|
+
const content = this.getText();
|
|
65
|
+
this.setText(content.slice(0, start) + text + content.slice(end));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.WritableDocument = WritableDocument;
|
|
69
|
+
//# sourceMappingURL=DocumentBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentBase.js","sourceRoot":"","sources":["../../../../src/lib/documents/DocumentBase.ts"],"names":[],"mappings":";;;AACA,mCAA+D;AAE/D;;GAEG;AACH,MAAsB,gBAAgB;IAAtC;QAgBI;;WAEG;QACI,YAAO,GAAG,CAAC,CAAC;IAiDvB,CAAC;IA1CG;;OAEG;IACH,aAAa;QACT,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,MAAc;QACrB,OAAO,IAAA,kBAAU,EAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,QAAkB;QACvB,OAAO,IAAA,gBAAQ,EAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACrE,CAAC;IAEO,cAAc;QAClB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,WAAW,GAAG,IAAA,sBAAc,EAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAChD,CAAC;CAGJ;AApED,4CAoEC;AAED;;GAEG;AACH,MAAsB,gBAAiB,SAAQ,gBAAgB;IAQ3D;;;;;OAKG;IACH,MAAM,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;QAC3C,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACtE,CAAC;CACJ;AAnBD,4CAmBC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TextDocumentContentChangeEvent, TextDocumentItem, VersionedTextDocumentIdentifier } from 'vscode-languageserver';
|
|
2
|
+
import { Document } from './Document';
|
|
3
|
+
export type DocumentEvent = 'documentOpen' | 'documentChange' | 'documentClose';
|
|
4
|
+
/**
|
|
5
|
+
* Manages svelte documents
|
|
6
|
+
*/
|
|
7
|
+
export declare class DocumentManager {
|
|
8
|
+
private createDocument;
|
|
9
|
+
private emitter;
|
|
10
|
+
private documents;
|
|
11
|
+
private locked;
|
|
12
|
+
private deleteCandidates;
|
|
13
|
+
constructor(createDocument: (textDocument: Pick<TextDocumentItem, 'text' | 'uri'>) => Document, options?: {
|
|
14
|
+
useCaseSensitiveFileNames: boolean;
|
|
15
|
+
});
|
|
16
|
+
openClientDocument(textDocument: Pick<TextDocumentItem, 'text' | 'uri'>): Document;
|
|
17
|
+
openDocument(textDocument: Pick<TextDocumentItem, 'text' | 'uri'>, openedByClient: boolean): Document;
|
|
18
|
+
lockDocument(uri: string): void;
|
|
19
|
+
markAsOpenedInClient(uri: string): void;
|
|
20
|
+
getAllOpenedByClient(): [string, Document][];
|
|
21
|
+
isOpenedInClient(uri: string): boolean;
|
|
22
|
+
releaseDocument(uri: string): void;
|
|
23
|
+
closeDocument(uri: string): void;
|
|
24
|
+
updateDocument(textDocument: VersionedTextDocumentIdentifier, changes: TextDocumentContentChangeEvent[]): void;
|
|
25
|
+
on(name: DocumentEvent, listener: (document: Document) => void): void;
|
|
26
|
+
get(uri: string): Document | undefined;
|
|
27
|
+
private notify;
|
|
28
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DocumentManager = void 0;
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
+
const fileCollection_1 = require("./fileCollection");
|
|
11
|
+
/**
|
|
12
|
+
* Manages svelte documents
|
|
13
|
+
*/
|
|
14
|
+
class DocumentManager {
|
|
15
|
+
constructor(createDocument, options = {
|
|
16
|
+
useCaseSensitiveFileNames: typescript_1.default.sys.useCaseSensitiveFileNames
|
|
17
|
+
}) {
|
|
18
|
+
this.createDocument = createDocument;
|
|
19
|
+
this.emitter = new events_1.EventEmitter();
|
|
20
|
+
this.documents = new fileCollection_1.FileMap(options.useCaseSensitiveFileNames);
|
|
21
|
+
this.locked = new fileCollection_1.FileSet(options.useCaseSensitiveFileNames);
|
|
22
|
+
this.deleteCandidates = new fileCollection_1.FileSet(options.useCaseSensitiveFileNames);
|
|
23
|
+
}
|
|
24
|
+
openClientDocument(textDocument) {
|
|
25
|
+
return this.openDocument(textDocument, /**openedByClient */ true);
|
|
26
|
+
}
|
|
27
|
+
openDocument(textDocument, openedByClient) {
|
|
28
|
+
textDocument = {
|
|
29
|
+
...textDocument,
|
|
30
|
+
uri: (0, utils_1.normalizeUri)(textDocument.uri)
|
|
31
|
+
};
|
|
32
|
+
let document;
|
|
33
|
+
if (this.documents.has(textDocument.uri)) {
|
|
34
|
+
document = this.documents.get(textDocument.uri);
|
|
35
|
+
// open state should only be updated when the document is closed
|
|
36
|
+
document.openedByClient ||= openedByClient;
|
|
37
|
+
document.setText(textDocument.text);
|
|
38
|
+
this.notify('documentChange', document);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
document = this.createDocument(textDocument);
|
|
42
|
+
document.openedByClient = openedByClient;
|
|
43
|
+
this.documents.set(textDocument.uri, document);
|
|
44
|
+
this.notify('documentOpen', document);
|
|
45
|
+
}
|
|
46
|
+
return document;
|
|
47
|
+
}
|
|
48
|
+
lockDocument(uri) {
|
|
49
|
+
this.locked.add((0, utils_1.normalizeUri)(uri));
|
|
50
|
+
}
|
|
51
|
+
markAsOpenedInClient(uri) {
|
|
52
|
+
const document = this.documents.get((0, utils_1.normalizeUri)(uri));
|
|
53
|
+
if (document) {
|
|
54
|
+
document.openedByClient = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
getAllOpenedByClient() {
|
|
58
|
+
return Array.from(this.documents.entries()).filter((doc) => doc[1].openedByClient);
|
|
59
|
+
}
|
|
60
|
+
isOpenedInClient(uri) {
|
|
61
|
+
const document = this.documents.get((0, utils_1.normalizeUri)(uri));
|
|
62
|
+
return !!document?.openedByClient;
|
|
63
|
+
}
|
|
64
|
+
releaseDocument(uri) {
|
|
65
|
+
uri = (0, utils_1.normalizeUri)(uri);
|
|
66
|
+
this.locked.delete(uri);
|
|
67
|
+
const document = this.documents.get(uri);
|
|
68
|
+
if (document) {
|
|
69
|
+
document.openedByClient = false;
|
|
70
|
+
}
|
|
71
|
+
if (this.deleteCandidates.has(uri)) {
|
|
72
|
+
this.deleteCandidates.delete(uri);
|
|
73
|
+
this.closeDocument(uri);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
closeDocument(uri) {
|
|
77
|
+
uri = (0, utils_1.normalizeUri)(uri);
|
|
78
|
+
const document = this.documents.get(uri);
|
|
79
|
+
if (!document) {
|
|
80
|
+
throw new Error('Cannot call methods on an unopened document');
|
|
81
|
+
}
|
|
82
|
+
this.notify('documentClose', document);
|
|
83
|
+
// Some plugin may prevent a document from actually being closed.
|
|
84
|
+
if (!this.locked.has(uri)) {
|
|
85
|
+
this.documents.delete(uri);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.deleteCandidates.add(uri);
|
|
89
|
+
}
|
|
90
|
+
document.openedByClient = false;
|
|
91
|
+
}
|
|
92
|
+
updateDocument(textDocument, changes) {
|
|
93
|
+
const document = this.documents.get((0, utils_1.normalizeUri)(textDocument.uri));
|
|
94
|
+
if (!document) {
|
|
95
|
+
throw new Error('Cannot call methods on an unopened document');
|
|
96
|
+
}
|
|
97
|
+
for (const change of changes) {
|
|
98
|
+
let start = 0;
|
|
99
|
+
let end = 0;
|
|
100
|
+
if ('range' in change) {
|
|
101
|
+
start = document.offsetAt(change.range.start);
|
|
102
|
+
end = document.offsetAt(change.range.end);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
end = document.getTextLength();
|
|
106
|
+
}
|
|
107
|
+
document.update(change.text, start, end);
|
|
108
|
+
}
|
|
109
|
+
this.notify('documentChange', document);
|
|
110
|
+
}
|
|
111
|
+
on(name, listener) {
|
|
112
|
+
this.emitter.on(name, listener);
|
|
113
|
+
}
|
|
114
|
+
get(uri) {
|
|
115
|
+
return this.documents.get((0, utils_1.normalizeUri)(uri));
|
|
116
|
+
}
|
|
117
|
+
notify(name, document) {
|
|
118
|
+
this.emitter.emit(name, document);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.DocumentManager = DocumentManager;
|
|
122
|
+
//# sourceMappingURL=DocumentManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentManager.js","sourceRoot":"","sources":["../../../../src/lib/documents/DocumentManager.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAsC;AAOtC,uCAA2C;AAC3C,4DAA4B;AAC5B,qDAAoD;AAIpD;;GAEG;AACH,MAAa,eAAe;IAMxB,YACY,cAAkF,EAC1F,UAAkD;QAC9C,yBAAyB,EAAE,oBAAE,CAAC,GAAG,CAAC,yBAAyB;KAC9D;QAHO,mBAAc,GAAd,cAAc,CAAoE;QANtF,YAAO,GAAG,IAAI,qBAAY,EAAE,CAAC;QAWjC,IAAI,CAAC,SAAS,GAAG,IAAI,wBAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,IAAI,wBAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC7D,IAAI,CAAC,gBAAgB,GAAG,IAAI,wBAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC3E,CAAC;IAED,kBAAkB,CAAC,YAAoD;QACnE,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACtE,CAAC;IAED,YAAY,CACR,YAAoD,EACpD,cAAuB;QAEvB,YAAY,GAAG;YACX,GAAG,YAAY;YACf,GAAG,EAAE,IAAA,oBAAY,EAAC,YAAY,CAAC,GAAG,CAAC;SACtC,CAAC;QAEF,IAAI,QAAkB,CAAC;QACvB,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;YACvC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAE,CAAC;YACjD,gEAAgE;YAChE,QA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SymbolInformation, LocationLink, TextDocumentEdit, CodeAction, SelectionRange, TextEdit, InsertReplaceEdit, Location } from 'vscode-languageserver';
|
|
2
|
+
import { TagInformation } from './utils';
|
|
3
|
+
import { TraceMap } from '@jridgewell/trace-mapping';
|
|
4
|
+
export interface FilePosition extends Position {
|
|
5
|
+
uri?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DocumentMapper {
|
|
8
|
+
/**
|
|
9
|
+
* Map the generated position to the original position
|
|
10
|
+
* @param generatedPosition Position in fragment
|
|
11
|
+
*/
|
|
12
|
+
getOriginalPosition(generatedPosition: Position): Position;
|
|
13
|
+
/**
|
|
14
|
+
* Map the generated position to the original position.
|
|
15
|
+
* Differs from getOriginalPosition this might maps to different file
|
|
16
|
+
* @param generatedPosition Position in fragment
|
|
17
|
+
*/
|
|
18
|
+
getOriginalFilePosition?(generatedPosition: Position): FilePosition;
|
|
19
|
+
/**
|
|
20
|
+
* Map the original position to the generated position
|
|
21
|
+
* @param originalPosition Position in parent
|
|
22
|
+
*/
|
|
23
|
+
getGeneratedPosition(originalPosition: Position): Position;
|
|
24
|
+
/**
|
|
25
|
+
* Returns true if the given original position is inside of the generated map
|
|
26
|
+
* @param pos Position in original
|
|
27
|
+
*/
|
|
28
|
+
isInGenerated(pos: Position): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Get document URL
|
|
31
|
+
*/
|
|
32
|
+
getURL(): string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Does not map, returns positions as is.
|
|
36
|
+
*/
|
|
37
|
+
export declare class IdentityMapper implements DocumentMapper {
|
|
38
|
+
private url;
|
|
39
|
+
private parent?;
|
|
40
|
+
constructor(url: string, parent?: DocumentMapper | undefined);
|
|
41
|
+
getOriginalPosition(generatedPosition: Position): Position;
|
|
42
|
+
getGeneratedPosition(originalPosition: Position): Position;
|
|
43
|
+
isInGenerated(position: Position): boolean;
|
|
44
|
+
getURL(): string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Maps positions in a fragment relative to a parent.
|
|
48
|
+
*/
|
|
49
|
+
export declare class FragmentMapper implements DocumentMapper {
|
|
50
|
+
private originalText;
|
|
51
|
+
private tagInfo;
|
|
52
|
+
private url;
|
|
53
|
+
private lineOffsetsOriginal;
|
|
54
|
+
private lineOffsetsGenerated;
|
|
55
|
+
constructor(originalText: string, tagInfo: TagInformation, url: string);
|
|
56
|
+
getOriginalPosition(generatedPosition: Position): Position;
|
|
57
|
+
private offsetInParent;
|
|
58
|
+
getGeneratedPosition(originalPosition: Position): Position;
|
|
59
|
+
isInGenerated(pos: Position): boolean;
|
|
60
|
+
getURL(): string;
|
|
61
|
+
}
|
|
62
|
+
export declare class SourceMapDocumentMapper implements DocumentMapper {
|
|
63
|
+
protected traceMap: TraceMap;
|
|
64
|
+
protected sourceUri: string;
|
|
65
|
+
private parent?;
|
|
66
|
+
constructor(traceMap: TraceMap, sourceUri: string, parent?: DocumentMapper | undefined);
|
|
67
|
+
getOriginalPosition(generatedPosition: Position): Position;
|
|
68
|
+
getGeneratedPosition(originalPosition: Position): Position;
|
|
69
|
+
isInGenerated(position: Position): boolean;
|
|
70
|
+
getURL(): string;
|
|
71
|
+
}
|
|
72
|
+
export declare function mapRangeToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, range: Range): Range;
|
|
73
|
+
export declare function mapLocationToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition' | 'getURL' | 'getOriginalFilePosition'>, range: Range): Location;
|
|
74
|
+
export declare function mapRangeToGenerated(fragment: DocumentMapper, range: Range): Range;
|
|
75
|
+
export declare function mapCompletionItemToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, item: CompletionItem): CompletionItem;
|
|
76
|
+
export declare function mapHoverToParent(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, hover: Hover): Hover;
|
|
77
|
+
export declare function mapObjWithRangeToOriginal<T extends {
|
|
78
|
+
range: Range;
|
|
79
|
+
}>(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, objWithRange: T): T;
|
|
80
|
+
export declare function mapInsertReplaceEditToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, edit: InsertReplaceEdit): InsertReplaceEdit;
|
|
81
|
+
export declare function mapEditToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, edit: TextEdit | InsertReplaceEdit): TextEdit | InsertReplaceEdit;
|
|
82
|
+
export declare function mapDiagnosticToGenerated(fragment: DocumentMapper, diagnostic: Diagnostic): Diagnostic;
|
|
83
|
+
export declare function mapColorPresentationToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, presentation: ColorPresentation): ColorPresentation;
|
|
84
|
+
export declare function mapSymbolInformationToOriginal(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, info: SymbolInformation): SymbolInformation;
|
|
85
|
+
export declare function mapLocationLinkToOriginal(fragment: DocumentMapper, def: LocationLink): LocationLink;
|
|
86
|
+
export declare function mapTextDocumentEditToOriginal(fragment: DocumentMapper, edit: TextDocumentEdit): TextDocumentEdit;
|
|
87
|
+
export declare function mapCodeActionToOriginal(fragment: DocumentMapper, codeAction: CodeAction): CodeAction;
|
|
88
|
+
export declare function mapSelectionRangeToParent(fragment: Pick<DocumentMapper, 'getOriginalPosition'>, selectionRange: SelectionRange): SelectionRange;
|