@zentryc5t/ts-plugin-for-bruno 3.1.0 → 3.2.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.
Files changed (54) hide show
  1. package/README.md +4 -0
  2. package/out/codeBlocks/bruCodeBlocks.js +71 -0
  3. package/out/codeBlocks/bruCodeBlocks.js.map +1 -0
  4. package/out/codeChanges/codeChanges.js +144 -0
  5. package/out/codeChanges/codeChanges.js.map +1 -0
  6. package/out/collection/collectionFormat.js +69 -0
  7. package/out/collection/collectionFormat.js.map +1 -0
  8. package/out/constants.js +36 -0
  9. package/out/constants.js.map +1 -0
  10. package/out/diagnostics/filterDefaultDiagnostics.js +81 -0
  11. package/out/diagnostics/filterDefaultDiagnostics.js.map +1 -0
  12. package/out/fileContent.js +28 -0
  13. package/out/fileContent.js.map +1 -0
  14. package/out/fileTypes.js +16 -0
  15. package/out/fileTypes.js.map +1 -0
  16. package/out/index.js +18 -297
  17. package/out/index.js.map +1 -1
  18. package/out/languageService/codeChangeOverrides.js +40 -0
  19. package/out/languageService/codeChangeOverrides.js.map +1 -0
  20. package/out/languageService/diagnosticsOverrides.js +41 -0
  21. package/out/languageService/diagnosticsOverrides.js.map +1 -0
  22. package/out/languageService/formattingOverrides.js +18 -0
  23. package/out/languageService/formattingOverrides.js.map +1 -0
  24. package/out/languageService/navigationOverrides.js +98 -0
  25. package/out/languageService/navigationOverrides.js.map +1 -0
  26. package/out/pluginConfiguration.js +29 -0
  27. package/out/pluginConfiguration.js.map +1 -0
  28. package/out/yamlFiles/getIndentationOfScripts.js +24 -0
  29. package/out/yamlFiles/getIndentationOfScripts.js.map +1 -0
  30. package/out/yamlFiles/maskYamlFileContent.js +126 -0
  31. package/out/yamlFiles/maskYamlFileContent.js.map +1 -0
  32. package/out/yamlFiles/maskYamlFilesForTypescriptServer.js +94 -0
  33. package/out/yamlFiles/maskYamlFilesForTypescriptServer.js.map +1 -0
  34. package/package.json +3 -2
  35. package/src/codeBlocks/bruCodeBlocks.ts +66 -0
  36. package/src/codeChanges/codeChanges.ts +182 -0
  37. package/src/collection/collectionFormat.ts +96 -0
  38. package/src/constants.test.ts +12 -0
  39. package/src/constants.ts +31 -0
  40. package/src/diagnostics/filterDefaultDiagnostics.ts +145 -0
  41. package/src/fileContent.ts +38 -0
  42. package/src/fileTypes.ts +13 -0
  43. package/src/index.test.ts +329 -0
  44. package/src/index.ts +24 -499
  45. package/src/languageService/codeChangeOverrides.ts +90 -0
  46. package/src/languageService/diagnosticsOverrides.ts +65 -0
  47. package/src/languageService/formattingOverrides.ts +42 -0
  48. package/src/languageService/navigationOverrides.ts +201 -0
  49. package/src/pluginConfiguration.ts +34 -0
  50. package/src/yamlFiles/getIndentationOfScripts.ts +34 -0
  51. package/src/yamlFiles/maskYamlFileContent.test.ts +213 -0
  52. package/src/yamlFiles/maskYamlFileContent.ts +179 -0
  53. package/src/yamlFiles/maskYamlFilesForTypescriptServer.ts +85 -0
  54. package/tsconfig.json +2 -1
@@ -0,0 +1,85 @@
1
+ import * as ts from "typescript/lib/tsserverlibrary";
2
+ import { isFileFromYamlCollection } from "../collection/collectionFormat";
3
+ import { originalSnapshotGettersForHosts } from "../fileContent";
4
+ import { isYamlFile } from "../fileTypes";
5
+ import { PluginConfiguration } from "../pluginConfiguration";
6
+ import {
7
+ maskYamlCollectionFileContent,
8
+ maskYamlFileContent,
9
+ } from "./maskYamlFileContent";
10
+
11
+ /**
12
+ * The Typescript server parses Yaml files like Typescript files, so that the Yaml content would affect the meaning of the code within scripts.
13
+ * Therefore, the Typescript server only gets to see the code of scripts within Yaml collection files (see `maskYamlCollectionFileContent`).
14
+ * All other Yaml files are masked completely. The same applies to Yaml collection files, as long as Yaml collections are not supported.
15
+ */
16
+ export function maskYamlFilesForTypescriptServer(
17
+ info: ts.server.PluginCreateInfo,
18
+ configuration: PluginConfiguration,
19
+ ) {
20
+ const host = info.languageServiceHost;
21
+
22
+ // Masking already masked content would remove all scripts.
23
+ if (originalSnapshotGettersForHosts.has(host)) {
24
+ return;
25
+ }
26
+
27
+ const getOriginalSnapshot = host.getScriptSnapshot.bind(host);
28
+ const getOriginalScriptVersion = host.getScriptVersion.bind(host);
29
+ originalSnapshotGettersForHosts.set(host, getOriginalSnapshot);
30
+ // A new snapshot is only created, if the content of a file or the configuration changes.
31
+ let maskedSnapshots = new WeakMap<ts.IScriptSnapshot, ts.IScriptSnapshot>();
32
+ let configurationVersion = 0;
33
+
34
+ configuration.onDidChange(() => {
35
+ maskedSnapshots = new WeakMap();
36
+ configurationVersion++;
37
+ // The project is not set when the plugin is used without a Typescript server (e.g. in tests).
38
+ if (info.project) {
39
+ info.project.refreshDiagnostics();
40
+ }
41
+ });
42
+
43
+ // The Typescript server only requests a new snapshot for a file, if the project version and the version of the file change.
44
+ if (host.getProjectVersion) {
45
+ const getOriginalProjectVersion = host.getProjectVersion.bind(host);
46
+ host.getProjectVersion = () =>
47
+ `${getOriginalProjectVersion()}-${configurationVersion}`;
48
+ }
49
+
50
+ host.getScriptVersion = (fileName) =>
51
+ isYamlFile(fileName)
52
+ ? `${getOriginalScriptVersion(fileName)}-${configurationVersion}`
53
+ : getOriginalScriptVersion(fileName);
54
+
55
+ host.getScriptSnapshot = (fileName) => {
56
+ const originalSnapshot = getOriginalSnapshot(fileName);
57
+
58
+ if (!originalSnapshot || !isYamlFile(fileName)) {
59
+ return originalSnapshot;
60
+ }
61
+
62
+ const cachedSnapshot = maskedSnapshots.get(originalSnapshot);
63
+
64
+ if (cachedSnapshot) {
65
+ return cachedSnapshot;
66
+ }
67
+
68
+ const originalContent = originalSnapshot.getText(
69
+ 0,
70
+ originalSnapshot.getLength(),
71
+ );
72
+
73
+ // Snapshots created from a string do not support incremental parsing, so the file is always parsed completely.
74
+ const maskedSnapshot = ts.ScriptSnapshot.fromString(
75
+ configuration.isYamlCollectionSupportEnabled() &&
76
+ isFileFromYamlCollection(info, fileName)
77
+ ? maskYamlCollectionFileContent(fileName, originalContent)
78
+ : maskYamlFileContent(originalContent),
79
+ );
80
+
81
+ maskedSnapshots.set(originalSnapshot, maskedSnapshot);
82
+
83
+ return maskedSnapshot;
84
+ };
85
+ }
package/tsconfig.json CHANGED
@@ -4,5 +4,6 @@
4
4
  "rootDir": "./src",
5
5
  "outDir": "out",
6
6
  "types": ["node"]
7
- }
7
+ },
8
+ "exclude": ["node_modules", "out", "**/*.test.ts"]
8
9
  }