@zentryc5t/ts-plugin-for-bruno 1.0.4 → 1.0.5
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/out/index.js +70 -24
- package/out/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +113 -33
package/out/index.js
CHANGED
|
@@ -29,7 +29,9 @@ function init(_modules) {
|
|
|
29
29
|
// Do not show diagnostics that only make sense for Typescript files.
|
|
30
30
|
// Bru file code blocks should be treated like Javascript functions instead.
|
|
31
31
|
// A list of diagnostics can be found here: https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
|
|
32
|
-
({ code }) => (code < 7043 || code > 7050) &&
|
|
32
|
+
({ code }) => (code < 7043 || code > 7050) &&
|
|
33
|
+
code != 80001 &&
|
|
34
|
+
code != 80004);
|
|
33
35
|
};
|
|
34
36
|
// All hovers are provided by the extension implementation
|
|
35
37
|
proxy.getQuickInfoAtPosition = (fileName, position) => {
|
|
@@ -44,18 +46,15 @@ function init(_modules) {
|
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
function filterDefaultDiagnostics(info, fileName, defaultDiagnostics) {
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let fileContent = undefined;
|
|
52
|
-
const scriptSnapshot = info.languageServiceHost.getScriptSnapshot(fileName);
|
|
53
|
-
if (scriptSnapshot) {
|
|
54
|
-
fileContent = scriptSnapshot.getText(0, scriptSnapshot.getLength());
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
fileContent = info.languageServiceHost.readFile(fileName);
|
|
49
|
+
if (isJsFileFromBrunoCollection(info, fileName)) {
|
|
50
|
+
const fileContent = getFileContent(info, fileName);
|
|
51
|
+
if (!fileContent) {
|
|
52
|
+
return [];
|
|
58
53
|
}
|
|
54
|
+
return filterOutDiagnosticsForInbuiltRuntimeFunctions(defaultDiagnostics, fileContent);
|
|
55
|
+
}
|
|
56
|
+
else if (isBrunoFile(fileName)) {
|
|
57
|
+
const fileContent = getFileContent(info, fileName);
|
|
59
58
|
if (!fileContent) {
|
|
60
59
|
return [];
|
|
61
60
|
}
|
|
@@ -66,20 +65,14 @@ function filterDefaultDiagnostics(info, fileName, defaultDiagnostics) {
|
|
|
66
65
|
indizes.push({ blockName, ...indizesForBlock });
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
|
-
if (indizes.length
|
|
70
|
-
return defaultDiagnostics.filter(({ start, length }) => start != undefined &&
|
|
71
|
-
length != undefined &&
|
|
72
|
-
indizes.some(({ startIndex: blockStart, endIndex: blockEnd }) => start >= blockStart && start <= blockEnd) &&
|
|
73
|
-
// Do not show diagnostics for functions that are provided by Bruno at runtime
|
|
74
|
-
!["bru", "req", "res", "test", "expect"].includes(fileContent.substring(start, start + length)) &&
|
|
75
|
-
// Avoid showing incorrect error when using `require`
|
|
76
|
-
// (the error seems to only occur for short periods of time when typescript type definitions have not been reloaded for a while)
|
|
77
|
-
fileContent.substring(start, start + length) !=
|
|
78
|
-
"require");
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
68
|
+
if (indizes.length == 0) {
|
|
81
69
|
return [];
|
|
82
70
|
}
|
|
71
|
+
return filterOutDiagnosticsForInbuiltRuntimeFunctions(defaultDiagnostics.filter(({ start }) => start != undefined &&
|
|
72
|
+
indizes.some(({ startIndex: blockStart, endIndex: blockEnd }) => start >= blockStart && start <= blockEnd)), fileContent);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return defaultDiagnostics;
|
|
83
76
|
}
|
|
84
77
|
}
|
|
85
78
|
function getCodeBlockStartAndEndIndex(fullTextContent, blockName) {
|
|
@@ -104,6 +97,59 @@ function getCodeBlockStartAndEndIndex(fullTextContent, blockName) {
|
|
|
104
97
|
endIndex: blockStartIndex + blockNodeInSubDocument.end,
|
|
105
98
|
};
|
|
106
99
|
}
|
|
100
|
+
function isJsFileFromBrunoCollection(info, fileName) {
|
|
101
|
+
return (0, path_1.extname)(fileName) == ".js" && isInABrunoCollection(info, fileName);
|
|
102
|
+
}
|
|
103
|
+
function filterOutDiagnosticsForInbuiltRuntimeFunctions(diagnosticsToFilter, fileContent) {
|
|
104
|
+
return diagnosticsToFilter.filter(({ start, length }) => start != undefined &&
|
|
105
|
+
length != undefined &&
|
|
106
|
+
// Do not show diagnostics for functions that are provided by Bruno at runtime
|
|
107
|
+
!["bru", "req", "res", "test", "expect"].includes(fileContent.substring(start, start + length)) &&
|
|
108
|
+
// Avoid showing incorrect error when using `require`
|
|
109
|
+
// (the error seems to only occur for short periods of time when typescript type definitions have not been reloaded for a while)
|
|
110
|
+
fileContent.substring(start, start + length) != "require");
|
|
111
|
+
}
|
|
112
|
+
function getFileContent(info, fileName) {
|
|
113
|
+
const scriptSnapshot = info.languageServiceHost.getScriptSnapshot(fileName);
|
|
114
|
+
if (scriptSnapshot) {
|
|
115
|
+
return scriptSnapshot.getText(0, scriptSnapshot.getLength());
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return info.languageServiceHost.readFile(fileName);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function isInABrunoCollection(info, fileName) {
|
|
122
|
+
let currentDirectory = (0, path_1.dirname)(fileName);
|
|
123
|
+
let isCollectionRoot = isACollectionRootFolder(info, currentDirectory);
|
|
124
|
+
while (info.serverHost.directoryExists(currentDirectory) &&
|
|
125
|
+
!isCollectionRoot &&
|
|
126
|
+
(0, path_1.dirname)(currentDirectory) != currentDirectory // dirname of a base folder in the file system seems to return the input folder again
|
|
127
|
+
) {
|
|
128
|
+
currentDirectory = (0, path_1.dirname)(currentDirectory);
|
|
129
|
+
isCollectionRoot = isACollectionRootFolder(info, currentDirectory);
|
|
130
|
+
}
|
|
131
|
+
return isCollectionRoot;
|
|
132
|
+
}
|
|
133
|
+
function isACollectionRootFolder(info, directoryPath) {
|
|
134
|
+
return info.serverHost
|
|
135
|
+
.readDirectory(directoryPath, undefined, undefined, undefined, 1)
|
|
136
|
+
.some((fileName) => {
|
|
137
|
+
if (!fileName.endsWith("bruno.json")) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
const content = info.languageServiceHost.readFile(fileName);
|
|
141
|
+
if (!content) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const parsedContent = JSON.parse(content);
|
|
146
|
+
return parsedContent && parsedContent.type == "collection";
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
107
153
|
function isBrunoFile(fileName) {
|
|
108
154
|
return (0, path_1.extname)(fileName) == ".bru";
|
|
109
155
|
}
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+BAAwC;AACxC,qDAAqD;AAErD,SAAS,IAAI,CAAC,QAEb;IACG,SAAS,MAAM,CAAC,IAAgC;QAC5C,0BAA0B;QAC1B,MAAM,KAAK,GAAuB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEtD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CACvB,IAAI,CAAC,eAAe,CACS,EAAE,CAAC;YAChC,MAAM,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAE,CAAC;YACnC,yEAAyE;YACzE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;YAC9B,yEAAyE;YACzE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;QAED,KAAK,CAAC,uBAAuB,GAAG,CAAC,QAAQ,EAAE,EAAE;YACzC,OAAO,wBAAwB,CAC3B,IAAI,EACJ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CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extname } from "path";
|
|
1
|
+
import { dirname, extname } from "path";
|
|
2
2
|
import * as ts from "typescript/lib/tsserverlibrary";
|
|
3
3
|
|
|
4
4
|
function init(_modules: {
|
|
@@ -52,7 +52,10 @@ function init(_modules: {
|
|
|
52
52
|
// Do not show diagnostics that only make sense for Typescript files.
|
|
53
53
|
// Bru file code blocks should be treated like Javascript functions instead.
|
|
54
54
|
// A list of diagnostics can be found here: https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
|
|
55
|
-
({ code }) =>
|
|
55
|
+
({ code }) =>
|
|
56
|
+
(code < 7_043 || code > 7_050) &&
|
|
57
|
+
code != 80_001 &&
|
|
58
|
+
code != 80_004,
|
|
56
59
|
);
|
|
57
60
|
};
|
|
58
61
|
|
|
@@ -79,19 +82,20 @@ function filterDefaultDiagnostics(
|
|
|
79
82
|
fileName: string,
|
|
80
83
|
defaultDiagnostics: (ts.Diagnostic | ts.DiagnosticWithLocation)[],
|
|
81
84
|
) {
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
info.languageServiceHost.getScriptSnapshot(fileName);
|
|
88
|
-
|
|
89
|
-
if (scriptSnapshot) {
|
|
90
|
-
fileContent = scriptSnapshot.getText(0, scriptSnapshot.getLength());
|
|
91
|
-
} else {
|
|
92
|
-
fileContent = info.languageServiceHost.readFile(fileName);
|
|
85
|
+
if (isJsFileFromBrunoCollection(info, fileName)) {
|
|
86
|
+
const fileContent = getFileContent(info, fileName);
|
|
87
|
+
|
|
88
|
+
if (!fileContent) {
|
|
89
|
+
return [];
|
|
93
90
|
}
|
|
94
91
|
|
|
92
|
+
return filterOutDiagnosticsForInbuiltRuntimeFunctions(
|
|
93
|
+
defaultDiagnostics,
|
|
94
|
+
fileContent,
|
|
95
|
+
);
|
|
96
|
+
} else if (isBrunoFile(fileName)) {
|
|
97
|
+
const fileContent = getFileContent(info, fileName);
|
|
98
|
+
|
|
95
99
|
if (!fileContent) {
|
|
96
100
|
return [];
|
|
97
101
|
}
|
|
@@ -113,30 +117,23 @@ function filterDefaultDiagnostics(
|
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
if (indizes.length
|
|
117
|
-
return
|
|
118
|
-
|
|
120
|
+
if (indizes.length == 0) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return filterOutDiagnosticsForInbuiltRuntimeFunctions(
|
|
125
|
+
defaultDiagnostics.filter(
|
|
126
|
+
({ start }) =>
|
|
119
127
|
start != undefined &&
|
|
120
|
-
length != undefined &&
|
|
121
128
|
indizes.some(
|
|
122
129
|
({ startIndex: blockStart, endIndex: blockEnd }) =>
|
|
123
130
|
start >= blockStart && start <= blockEnd,
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
),
|
|
131
|
-
) &&
|
|
132
|
-
// Avoid showing incorrect error when using `require`
|
|
133
|
-
// (the error seems to only occur for short periods of time when typescript type definitions have not been reloaded for a while)
|
|
134
|
-
(fileContent as string).substring(start, start + length) !=
|
|
135
|
-
"require",
|
|
136
|
-
);
|
|
137
|
-
} else {
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
131
|
+
),
|
|
132
|
+
),
|
|
133
|
+
fileContent,
|
|
134
|
+
);
|
|
135
|
+
} else {
|
|
136
|
+
return defaultDiagnostics;
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
139
|
|
|
@@ -183,6 +180,89 @@ function getCodeBlockStartAndEndIndex(
|
|
|
183
180
|
};
|
|
184
181
|
}
|
|
185
182
|
|
|
183
|
+
function isJsFileFromBrunoCollection(
|
|
184
|
+
info: ts.server.PluginCreateInfo,
|
|
185
|
+
fileName: string,
|
|
186
|
+
) {
|
|
187
|
+
return extname(fileName) == ".js" && isInABrunoCollection(info, fileName);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function filterOutDiagnosticsForInbuiltRuntimeFunctions(
|
|
191
|
+
diagnosticsToFilter: (ts.Diagnostic | ts.DiagnosticWithLocation)[],
|
|
192
|
+
fileContent: string,
|
|
193
|
+
) {
|
|
194
|
+
return diagnosticsToFilter.filter(
|
|
195
|
+
({ start, length }) =>
|
|
196
|
+
start != undefined &&
|
|
197
|
+
length != undefined &&
|
|
198
|
+
// Do not show diagnostics for functions that are provided by Bruno at runtime
|
|
199
|
+
!["bru", "req", "res", "test", "expect"].includes(
|
|
200
|
+
fileContent.substring(start, start + length),
|
|
201
|
+
) &&
|
|
202
|
+
// Avoid showing incorrect error when using `require`
|
|
203
|
+
// (the error seems to only occur for short periods of time when typescript type definitions have not been reloaded for a while)
|
|
204
|
+
fileContent.substring(start, start + length) != "require",
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getFileContent(info: ts.server.PluginCreateInfo, fileName: string) {
|
|
209
|
+
const scriptSnapshot = info.languageServiceHost.getScriptSnapshot(fileName);
|
|
210
|
+
|
|
211
|
+
if (scriptSnapshot) {
|
|
212
|
+
return scriptSnapshot.getText(0, scriptSnapshot.getLength());
|
|
213
|
+
} else {
|
|
214
|
+
return info.languageServiceHost.readFile(fileName);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function isInABrunoCollection(
|
|
219
|
+
info: ts.server.PluginCreateInfo,
|
|
220
|
+
fileName: string,
|
|
221
|
+
) {
|
|
222
|
+
let currentDirectory = dirname(fileName);
|
|
223
|
+
let isCollectionRoot = isACollectionRootFolder(info, currentDirectory);
|
|
224
|
+
|
|
225
|
+
while (
|
|
226
|
+
info.serverHost.directoryExists(currentDirectory) &&
|
|
227
|
+
!isCollectionRoot &&
|
|
228
|
+
dirname(currentDirectory) != currentDirectory // dirname of a base folder in the file system seems to return the input folder again
|
|
229
|
+
) {
|
|
230
|
+
currentDirectory = dirname(currentDirectory);
|
|
231
|
+
isCollectionRoot = isACollectionRootFolder(info, currentDirectory);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return isCollectionRoot;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function isACollectionRootFolder(
|
|
238
|
+
info: ts.server.PluginCreateInfo,
|
|
239
|
+
directoryPath: string,
|
|
240
|
+
) {
|
|
241
|
+
return info.serverHost
|
|
242
|
+
.readDirectory(directoryPath, undefined, undefined, undefined, 1)
|
|
243
|
+
.some((fileName) => {
|
|
244
|
+
if (!fileName.endsWith("bruno.json")) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const content = info.languageServiceHost.readFile(fileName);
|
|
249
|
+
|
|
250
|
+
if (!content) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
const parsedContent = JSON.parse(content) as
|
|
256
|
+
| { type: string }
|
|
257
|
+
| undefined;
|
|
258
|
+
|
|
259
|
+
return parsedContent && parsedContent.type == "collection";
|
|
260
|
+
} catch {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
186
266
|
function isBrunoFile(fileName: string) {
|
|
187
267
|
return extname(fileName) == ".bru";
|
|
188
268
|
}
|