@marko/language-server 1.1.2 → 1.1.4

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/dist/index.js CHANGED
@@ -2011,6 +2011,9 @@ var import_language_tools16 = require("@marko/language-tools");
2011
2011
 
2012
2012
  // src/ts-plugin/host.ts
2013
2013
  var import_path6 = __toESM(require("path"));
2014
+ var defaultCompiler = __toESM(require("@marko/compiler"));
2015
+ var defaultConfig = __toESM(require("@marko/compiler/config"));
2016
+ var defaultTranslator = __toESM(require("@marko/translator-default"));
2014
2017
  var import_language_tools15 = require("@marko/language-tools");
2015
2018
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
2016
2019
  var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
@@ -2018,6 +2021,10 @@ import_language_tools15.Project.setDefaultTypePaths({
2018
2021
  internalTypesFile: import_path6.default.join(__dirname, "marko.internal.d.ts"),
2019
2022
  markoTypesFile: import_path6.default.join(__dirname, "marko.runtime.d.ts")
2020
2023
  });
2024
+ import_language_tools15.Project.setDefaultCompilerMeta(defaultCompiler, {
2025
+ ...defaultConfig,
2026
+ translator: defaultTranslator
2027
+ });
2021
2028
  function patch(ts2, configFile, extractCache3, resolutionCache, host, ps) {
2022
2029
  var _a, _b, _c;
2023
2030
  const processors = import_language_tools15.Processors.create({
@@ -3549,39 +3556,31 @@ var service = {
3549
3556
  );
3550
3557
  },
3551
3558
  async doComplete(doc, params, cancel) {
3552
- const itemsByLabel = /* @__PURE__ */ new Map();
3553
- await Promise.allSettled(
3554
- plugins.map(async (plugin) => {
3559
+ const results = await Promise.allSettled(
3560
+ plugins.map((plugin) => {
3555
3561
  var _a;
3556
- const cur = await ((_a = plugin.doComplete) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3557
- if (cancel.isCancellationRequested)
3558
- return;
3559
- if (cur) {
3560
- let curItems;
3561
- if (Array.isArray(cur)) {
3562
- curItems = cur;
3563
- } else {
3564
- curItems = cur.items;
3565
- }
3566
- for (const item of curItems) {
3567
- const { label } = item;
3568
- const existingItem = itemsByLabel.get(label);
3569
- if (existingItem) {
3570
- if ((existingItem.sortText || label) < (item.sortText || label)) {
3571
- itemsByLabel.set(label, item);
3572
- }
3573
- } else {
3574
- itemsByLabel.set(label, item);
3575
- }
3576
- }
3577
- }
3562
+ return (_a = plugin.doComplete) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3578
3563
  })
3579
3564
  );
3580
3565
  if (cancel.isCancellationRequested)
3581
3566
  return;
3582
- if (itemsByLabel.size) {
3583
- return { items: [...itemsByLabel.values()], isIncomplete: true };
3567
+ const itemsByLabel = /* @__PURE__ */ new Map();
3568
+ for (const result of results) {
3569
+ if (result.status !== "fulfilled" || !result.value)
3570
+ continue;
3571
+ for (const item of Array.isArray(result.value) ? result.value : result.value.items) {
3572
+ const { label } = item;
3573
+ const existingItem = itemsByLabel.get(label);
3574
+ if (existingItem) {
3575
+ if ((existingItem.sortText || label) < (item.sortText || label)) {
3576
+ itemsByLabel.set(label, item);
3577
+ }
3578
+ } else {
3579
+ itemsByLabel.set(label, item);
3580
+ }
3581
+ }
3584
3582
  }
3583
+ return { items: [...itemsByLabel.values()], isIncomplete: true };
3585
3584
  },
3586
3585
  async doCompletionResolve(item, cancel) {
3587
3586
  var _a;
@@ -3597,172 +3596,189 @@ var service = {
3597
3596
  }
3598
3597
  },
3599
3598
  async findDefinition(doc, params, cancel) {
3600
- let result;
3601
- await Promise.allSettled(
3602
- plugins.map(async (plugin) => {
3599
+ const results = await Promise.allSettled(
3600
+ plugins.map((plugin) => {
3603
3601
  var _a;
3604
- const cur = await ((_a = plugin.findDefinition) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3605
- if (cancel.isCancellationRequested)
3606
- return;
3607
- if (cur)
3608
- result = (result || []).concat(cur);
3602
+ return (_a = plugin.findDefinition) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3609
3603
  })
3610
3604
  );
3611
3605
  if (cancel.isCancellationRequested)
3612
3606
  return;
3613
- return result;
3607
+ let links;
3608
+ for (const result of results) {
3609
+ if (result.status !== "fulfilled" || !result.value)
3610
+ continue;
3611
+ links = (links || []).concat(result.value);
3612
+ }
3613
+ return links;
3614
3614
  },
3615
3615
  async findReferences(doc, params, cancel) {
3616
- let result;
3617
- await Promise.allSettled(
3618
- plugins.map(async (plugin) => {
3616
+ const results = await Promise.allSettled(
3617
+ plugins.map((plugin) => {
3619
3618
  var _a;
3620
- const cur = await ((_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3621
- if (cancel.isCancellationRequested)
3622
- return;
3623
- if (cur)
3624
- result = (result || []).concat(cur);
3619
+ return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3625
3620
  })
3626
3621
  );
3627
3622
  if (cancel.isCancellationRequested)
3628
3623
  return;
3629
- return result;
3624
+ let references;
3625
+ for (const result of results) {
3626
+ if (result.status !== "fulfilled" || !result.value)
3627
+ continue;
3628
+ references = (references || []).concat(result.value);
3629
+ }
3630
+ return references;
3630
3631
  },
3631
3632
  async findDocumentSymbols(doc, params, cancel) {
3632
- let result;
3633
- await Promise.allSettled(
3634
- plugins.map(async (plugin) => {
3633
+ const results = await Promise.allSettled(
3634
+ plugins.map((plugin) => {
3635
3635
  var _a;
3636
- const cur = await ((_a = plugin.findDocumentSymbols) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3637
- if (cancel.isCancellationRequested)
3638
- return;
3639
- if (cur)
3640
- result = (result || []).concat(cur);
3636
+ return (_a = plugin.findDocumentSymbols) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3641
3637
  })
3642
3638
  );
3643
3639
  if (cancel.isCancellationRequested)
3644
3640
  return;
3645
- return result;
3641
+ let symbols;
3642
+ for (const result of results) {
3643
+ if (result.status !== "fulfilled" || !result.value)
3644
+ continue;
3645
+ symbols = (symbols || []).concat(result.value);
3646
+ }
3647
+ return symbols;
3646
3648
  },
3647
3649
  async findDocumentLinks(doc, params, cancel) {
3648
- let result;
3649
- await Promise.allSettled(
3650
- plugins.map(async (plugin) => {
3650
+ const results = await Promise.allSettled(
3651
+ plugins.map((plugin) => {
3651
3652
  var _a;
3652
- const cur = await ((_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3653
- if (cancel.isCancellationRequested)
3654
- return;
3655
- if (cur)
3656
- result = (result || []).concat(cur);
3653
+ return (_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3657
3654
  })
3658
3655
  );
3659
3656
  if (cancel.isCancellationRequested)
3660
3657
  return;
3661
- return result;
3658
+ let links;
3659
+ for (const result of results) {
3660
+ if (result.status !== "fulfilled" || !result.value)
3661
+ continue;
3662
+ links = (links || []).concat(result.value);
3663
+ }
3664
+ return links;
3662
3665
  },
3663
3666
  async findDocumentHighlights(doc, params, cancel) {
3664
- let result;
3665
- await Promise.allSettled(
3666
- plugins.map(async (plugin) => {
3667
- var _a;
3668
- const cur = await ((_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3669
- if (cancel.isCancellationRequested)
3670
- return;
3671
- if (cur)
3672
- result = (result || []).concat(cur);
3673
- })
3667
+ const results = await Promise.allSettled(
3668
+ plugins.map(
3669
+ (plugin) => {
3670
+ var _a;
3671
+ return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3672
+ }
3673
+ )
3674
3674
  );
3675
3675
  if (cancel.isCancellationRequested)
3676
3676
  return;
3677
- return result;
3677
+ let highlights;
3678
+ for (const result of results) {
3679
+ if (result.status !== "fulfilled" || !result.value)
3680
+ continue;
3681
+ highlights = (highlights || []).concat(result.value);
3682
+ }
3683
+ return highlights;
3678
3684
  },
3679
3685
  async findDocumentColors(doc, params, cancel) {
3680
- let result;
3681
- await Promise.allSettled(
3682
- plugins.map(async (plugin) => {
3686
+ const results = await Promise.allSettled(
3687
+ plugins.map((plugin) => {
3683
3688
  var _a;
3684
- const cur = await ((_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3685
- if (cancel.isCancellationRequested)
3686
- return;
3687
- if (cur)
3688
- result = (result || []).concat(cur);
3689
+ return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3689
3690
  })
3690
3691
  );
3691
3692
  if (cancel.isCancellationRequested)
3692
3693
  return;
3693
- return result;
3694
+ let colors;
3695
+ for (const result of results) {
3696
+ if (result.status !== "fulfilled" || !result.value)
3697
+ continue;
3698
+ colors = (colors || []).concat(result.value);
3699
+ }
3700
+ return colors;
3694
3701
  },
3695
3702
  async getColorPresentations(doc, params, cancel) {
3696
- let result;
3697
- await Promise.allSettled(
3698
- plugins.map(async (plugin) => {
3699
- var _a;
3700
- const cur = await ((_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3701
- if (cancel.isCancellationRequested)
3702
- return;
3703
- if (cur)
3704
- result = (result || []).concat(cur);
3705
- })
3703
+ const results = await Promise.allSettled(
3704
+ plugins.map(
3705
+ (plugin) => {
3706
+ var _a;
3707
+ return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3708
+ }
3709
+ )
3706
3710
  );
3707
3711
  if (cancel.isCancellationRequested)
3708
3712
  return;
3709
- return result;
3713
+ let presentations;
3714
+ for (const result of results) {
3715
+ if (result.status !== "fulfilled" || !result.value)
3716
+ continue;
3717
+ presentations = (presentations || []).concat(result.value);
3718
+ }
3719
+ return presentations;
3710
3720
  },
3711
3721
  async doHover(doc, params, cancel) {
3712
- let result;
3713
- await Promise.allSettled(
3714
- plugins.map(async (plugin) => {
3722
+ const results = await Promise.allSettled(
3723
+ plugins.map((plugin) => {
3715
3724
  var _a;
3716
- const cur = await ((_a = plugin.doHover) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3717
- if (cancel.isCancellationRequested)
3718
- return;
3719
- if (cur) {
3720
- if (result) {
3721
- result.range = maxRange(result.range, cur.range);
3722
- result.contents = mergeHoverContents(result.contents, cur.contents);
3723
- } else {
3724
- result = cur;
3725
- }
3726
- }
3725
+ return (_a = plugin.doHover) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3727
3726
  })
3728
3727
  );
3729
- return result;
3728
+ if (cancel.isCancellationRequested)
3729
+ return;
3730
+ let hovers;
3731
+ for (const result of results) {
3732
+ if (result.status !== "fulfilled" || !result.value)
3733
+ continue;
3734
+ if (hovers) {
3735
+ hovers.range = maxRange(hovers.range, result.value.range);
3736
+ hovers.contents = mergeHoverContents(
3737
+ hovers.contents,
3738
+ result.value.contents
3739
+ );
3740
+ } else {
3741
+ hovers = result.value;
3742
+ }
3743
+ }
3744
+ return hovers;
3730
3745
  },
3731
3746
  async doRename(doc, params, cancel) {
3732
- let changes;
3733
- let changeAnnotations;
3734
- let documentChanges;
3735
- await Promise.allSettled(
3736
- plugins.map(async (plugin) => {
3747
+ const results = await Promise.allSettled(
3748
+ plugins.map((plugin) => {
3737
3749
  var _a;
3738
- const cur = await ((_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3739
- if (cancel.isCancellationRequested)
3740
- return;
3741
- if (cur) {
3742
- if (cur.changes) {
3743
- if (changes) {
3744
- changes = { ...changes };
3745
- for (const uri in cur.changes) {
3746
- changes[uri] = changes[uri] ? changes[uri].concat(cur.changes[uri]) : cur.changes[uri];
3747
- }
3748
- } else {
3749
- changes = cur.changes;
3750
- }
3751
- }
3752
- if (cur.changeAnnotations) {
3753
- changeAnnotations = changeAnnotations ? {
3754
- ...changeAnnotations,
3755
- ...cur.changeAnnotations
3756
- } : cur.changeAnnotations;
3757
- }
3758
- if (cur.documentChanges) {
3759
- documentChanges = documentChanges ? documentChanges.concat(cur.documentChanges) : cur.documentChanges;
3760
- }
3761
- }
3750
+ return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3762
3751
  })
3763
3752
  );
3764
3753
  if (cancel.isCancellationRequested)
3765
3754
  return;
3755
+ let changes;
3756
+ let changeAnnotations;
3757
+ let documentChanges;
3758
+ for (const result of results) {
3759
+ if (result.status !== "fulfilled" || !result.value)
3760
+ continue;
3761
+ const { value } = result;
3762
+ if (value.changes) {
3763
+ if (changes) {
3764
+ changes = { ...changes };
3765
+ for (const uri in value.changes) {
3766
+ changes[uri] = changes[uri] ? changes[uri].concat(value.changes[uri]) : value.changes[uri];
3767
+ }
3768
+ } else {
3769
+ changes = value.changes;
3770
+ }
3771
+ }
3772
+ if (value.changeAnnotations) {
3773
+ changeAnnotations = changeAnnotations ? {
3774
+ ...changeAnnotations,
3775
+ ...value.changeAnnotations
3776
+ } : value.changeAnnotations;
3777
+ }
3778
+ if (value.documentChanges) {
3779
+ documentChanges = documentChanges ? documentChanges.concat(value.documentChanges) : value.documentChanges;
3780
+ }
3781
+ }
3766
3782
  if (changes || changeAnnotations || documentChanges) {
3767
3783
  return {
3768
3784
  changes,
@@ -3772,32 +3788,36 @@ var service = {
3772
3788
  }
3773
3789
  },
3774
3790
  async doCodeActions(doc, params, cancel) {
3775
- let result;
3776
- await Promise.allSettled(
3777
- plugins.map(async (plugin) => {
3791
+ const results = await Promise.allSettled(
3792
+ plugins.map((plugin) => {
3778
3793
  var _a;
3779
- const cur = await ((_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3780
- if (cancel.isCancellationRequested)
3781
- return;
3782
- if (cur)
3783
- result = (result || []).concat(cur);
3794
+ return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3784
3795
  })
3785
3796
  );
3786
3797
  if (cancel.isCancellationRequested)
3787
3798
  return;
3788
- return result;
3799
+ let actions;
3800
+ for (const result of results) {
3801
+ if (result.status !== "fulfilled" || !result.value)
3802
+ continue;
3803
+ actions = (actions || []).concat(result.value);
3804
+ }
3805
+ return actions;
3789
3806
  },
3790
3807
  async doValidate(doc) {
3791
- let result;
3792
- await Promise.allSettled(
3793
- plugins.map(async (plugin) => {
3808
+ const results = await Promise.allSettled(
3809
+ plugins.map((plugin) => {
3794
3810
  var _a;
3795
- const cur = await ((_a = plugin.doValidate) == null ? void 0 : _a.call(plugin, doc));
3796
- if (cur)
3797
- result = (result || []).concat(cur);
3811
+ return (_a = plugin.doValidate) == null ? void 0 : _a.call(plugin, doc);
3798
3812
  })
3799
3813
  );
3800
- return result;
3814
+ let diagnostics;
3815
+ for (const result of results) {
3816
+ if (result.status !== "fulfilled" || !result.value)
3817
+ continue;
3818
+ diagnostics = (diagnostics || []).concat(result.value);
3819
+ }
3820
+ return diagnostics;
3801
3821
  },
3802
3822
  format: marko_default.format
3803
3823
  };