typescript-svelte-plugin 0.3.7 → 0.3.8

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.
@@ -7,10 +7,45 @@ const componentPostfix = '__SvelteComponent_';
7
7
  function decorateCompletions(ls, logger) {
8
8
  const getCompletionsAtPosition = ls.getCompletionsAtPosition;
9
9
  ls.getCompletionsAtPosition = (fileName, position, options) => {
10
+ var _a, _b, _c, _d;
10
11
  const completions = getCompletionsAtPosition(fileName, position, options);
11
12
  if (!completions) {
12
13
  return completions;
13
14
  }
15
+ // Add ./$types imports for SvelteKit since TypeScript is bad at it
16
+ if ((0, path_1.basename)(fileName).startsWith('+')) {
17
+ const $typeImports = new Map();
18
+ for (const c of completions.entries) {
19
+ if (((_a = c.source) === null || _a === void 0 ? void 0 : _a.includes('.svelte-kit/types')) && c.data) {
20
+ $typeImports.set(c.name, c);
21
+ }
22
+ }
23
+ for (const $typeImport of $typeImports.values()) {
24
+ // resolve path from FileName to svelte-kit/types
25
+ // src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
26
+ const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
27
+ const relativeFileName = (_b = fileName.split(routesFolder)[1]) === null || _b === void 0 ? void 0 : _b.slice(1);
28
+ if (relativeFileName) {
29
+ const modifiedSource = $typeImport.source.split('.svelte-kit/types')[0] +
30
+ // note the missing .d.ts at the end - TS wants it that way for some reason
31
+ `.svelte-kit/types/${routesFolder}/${(0, path_1.dirname)(relativeFileName)}/$types`;
32
+ completions.entries.push({
33
+ ...$typeImport,
34
+ // Ensure it's sorted above the other imports
35
+ sortText: !isNaN(Number($typeImport.sortText))
36
+ ? String(Number($typeImport.sortText) - 1)
37
+ : $typeImport.sortText,
38
+ source: modifiedSource,
39
+ data: {
40
+ ...$typeImport.data,
41
+ fileName: (_c = $typeImport.data.fileName) === null || _c === void 0 ? void 0 : _c.replace($typeImport.source, modifiedSource),
42
+ moduleSpecifier: (_d = $typeImport.data.moduleSpecifier) === null || _d === void 0 ? void 0 : _d.replace($typeImport.source, modifiedSource),
43
+ __is_sveltekit$typeImport: true
44
+ }
45
+ });
46
+ }
47
+ }
48
+ }
14
49
  return {
15
50
  ...completions,
16
51
  entries: completions.entries.map((entry) => {
@@ -27,36 +62,12 @@ function decorateCompletions(ls, logger) {
27
62
  };
28
63
  const getCompletionEntryDetails = ls.getCompletionEntryDetails;
29
64
  ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
30
- var _a, _b, _c, _d;
31
- let is$typeImport = false;
32
- const originalSource = source;
33
- const originalData = data ? { ...data } : undefined;
34
- if ((0, path_1.basename)(fileName).startsWith('+') && (source === null || source === void 0 ? void 0 : source.includes('.svelte-kit/types'))) {
35
- // resolve path from FileName to svelte-kit/types
36
- // src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
37
- const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
38
- const relativeFileName = (_a = fileName.split(routesFolder)[1]) === null || _a === void 0 ? void 0 : _a.slice(1);
39
- if (relativeFileName) {
40
- is$typeImport = true;
41
- source =
42
- source.split('.svelte-kit/types')[0] +
43
- // note the missing .d.ts at the end - TS wants it that way for some reason
44
- `.svelte-kit/types/${routesFolder}/${(0, path_1.dirname)(relativeFileName)}/$types`;
45
- if (data) {
46
- data.fileName = (_b = data.fileName) === null || _b === void 0 ? void 0 : _b.replace(originalSource, source);
47
- data.moduleSpecifier = (_c = data.moduleSpecifier) === null || _c === void 0 ? void 0 : _c.replace(originalSource, source);
48
- }
49
- }
50
- }
51
- let details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
52
- if (!details && is$typeImport) {
53
- // Try again
54
- is$typeImport = false;
55
- details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, originalSource, preferences, originalData);
56
- }
65
+ var _a;
66
+ const is$typeImport = data.__is_sveltekit$typeImport;
67
+ const details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
57
68
  if (details) {
58
69
  if (is$typeImport) {
59
- details.codeActions = (_d = details.codeActions) === null || _d === void 0 ? void 0 : _d.map((codeAction) => {
70
+ details.codeActions = (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((codeAction) => {
60
71
  codeAction.description = adjustPath(codeAction.description);
61
72
  codeAction.changes = codeAction.changes.map((change) => {
62
73
  change.textChanges = change.textChanges.map((textChange) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-svelte-plugin",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "A TypeScript Plugin providing Svelte intellisense",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {