@marko/language-server 1.1.1 → 1.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/dist/index.mjs CHANGED
@@ -13,13 +13,17 @@ import {
13
13
  TextDocumentSyncKind,
14
14
  createConnection
15
15
  } from "vscode-languageserver/node";
16
- import { Project as Project5 } from "@marko/language-tools";
16
+ import { Project as Project6 } from "@marko/language-tools";
17
17
 
18
18
  // src/utils/file.ts
19
19
  import path from "path";
20
20
  import { Project, parse } from "@marko/language-tools";
21
21
  import { URI } from "vscode-uri";
22
22
  var processorCaches = /* @__PURE__ */ new WeakMap();
23
+ function getFSDir(doc) {
24
+ const filename = getFSPath(doc);
25
+ return filename ? path.dirname(filename) : void 0;
26
+ }
23
27
  function getFSPath(doc) {
24
28
  return URI.parse(doc.uri).fsPath;
25
29
  }
@@ -1962,13 +1966,17 @@ function extractDocumentSymbols({
1962
1966
  import { TextEdit as TextEdit6 } from "vscode-languageserver";
1963
1967
  import * as prettier from "prettier";
1964
1968
  import * as markoPrettier from "prettier-plugin-marko";
1969
+ import { Project as Project3 } from "@marko/language-tools";
1965
1970
  var format2 = async (doc, params, cancel) => {
1966
1971
  try {
1972
+ const dir = getFSDir(doc);
1967
1973
  const filepath = getFSPath(doc);
1968
1974
  const text = doc.getText();
1969
1975
  const options = {
1970
1976
  parser: "marko",
1971
1977
  filepath,
1978
+ markoCompiler: Project3.getCompiler(dir),
1979
+ markoCompilerConfig: Project3.getConfig(dir),
1972
1980
  plugins: [markoPrettier],
1973
1981
  tabWidth: params.options.tabSize,
1974
1982
  useTabs: params.options.insertSpaces === false,
@@ -2019,25 +2027,32 @@ import { URI as URI6 } from "vscode-uri";
2019
2027
  import * as prettier2 from "prettier";
2020
2028
  import {
2021
2029
  NodeType as NodeType9,
2022
- Project as Project4,
2030
+ Project as Project5,
2023
2031
  ScriptLang,
2024
2032
  extractScript
2025
2033
  } from "@marko/language-tools";
2026
2034
 
2027
2035
  // src/ts-plugin/host.ts
2028
2036
  import path6 from "path";
2037
+ import * as defaultCompiler from "@marko/compiler";
2038
+ import * as defaultConfig from "@marko/compiler/config";
2039
+ import * as defaultTranslator from "@marko/translator-default";
2029
2040
  import {
2030
2041
  Processors,
2031
- Project as Project3,
2042
+ Project as Project4,
2032
2043
  getExt,
2033
2044
  isDefinitionFile
2034
2045
  } from "@marko/language-tools";
2035
2046
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
2036
2047
  var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
2037
- Project3.setDefaultTypePaths({
2048
+ Project4.setDefaultTypePaths({
2038
2049
  internalTypesFile: path6.join(__dirname, "marko.internal.d.ts"),
2039
2050
  markoTypesFile: path6.join(__dirname, "marko.runtime.d.ts")
2040
2051
  });
2052
+ Project4.setDefaultCompilerMeta(defaultCompiler, {
2053
+ ...defaultConfig,
2054
+ translator: defaultTranslator
2055
+ });
2041
2056
  function patch(ts2, configFile, extractCache3, resolutionCache, host, ps) {
2042
2057
  var _a, _b, _c;
2043
2058
  const processors = Processors.create({
@@ -2413,7 +2428,7 @@ var ScriptService = {
2413
2428
  return;
2414
2429
  const tsProject = getTSProject(filename);
2415
2430
  const extracted = processScript(doc, tsProject);
2416
- const lang = Project4.getScriptLang(
2431
+ const lang = Project5.getScriptLang(
2417
2432
  filename,
2418
2433
  tsProject.markoScriptLang,
2419
2434
  ts,
@@ -2797,8 +2812,8 @@ function processScript(doc, tsProject) {
2797
2812
  ts,
2798
2813
  parsed,
2799
2814
  lookup,
2800
- scriptLang: Project4.getScriptLang(filename, markoScriptLang, ts, host),
2801
- runtimeTypesCode: (_a = Project4.getTypeLibs(tsProject.rootDir, ts, host)) == null ? void 0 : _a.markoTypesCode
2815
+ scriptLang: Project5.getScriptLang(filename, markoScriptLang, ts, host),
2816
+ runtimeTypesCode: (_a = Project5.getTypeLibs(tsProject.rootDir, ts, host)) == null ? void 0 : _a.markoTypesCode
2802
2817
  });
2803
2818
  });
2804
2819
  }
@@ -2870,7 +2885,7 @@ function getTSProject(docFsPath) {
2870
2885
  }
2871
2886
  }
2872
2887
  const rootDir = configFile && path7.dirname(configFile) || process.cwd();
2873
- const cache = Project4.getCache(configFile && rootDir);
2888
+ const cache = Project5.getCache(configFile && rootDir);
2874
2889
  let projectCache = cache.get(getTSProject);
2875
2890
  let cached;
2876
2891
  if (projectCache) {
@@ -3575,39 +3590,31 @@ var service = {
3575
3590
  );
3576
3591
  },
3577
3592
  async doComplete(doc, params, cancel) {
3578
- const itemsByLabel = /* @__PURE__ */ new Map();
3579
- await Promise.allSettled(
3580
- plugins.map(async (plugin) => {
3593
+ const results = await Promise.allSettled(
3594
+ plugins.map((plugin) => {
3581
3595
  var _a;
3582
- const cur = await ((_a = plugin.doComplete) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3583
- if (cancel.isCancellationRequested)
3584
- return;
3585
- if (cur) {
3586
- let curItems;
3587
- if (Array.isArray(cur)) {
3588
- curItems = cur;
3589
- } else {
3590
- curItems = cur.items;
3591
- }
3592
- for (const item of curItems) {
3593
- const { label } = item;
3594
- const existingItem = itemsByLabel.get(label);
3595
- if (existingItem) {
3596
- if ((existingItem.sortText || label) < (item.sortText || label)) {
3597
- itemsByLabel.set(label, item);
3598
- }
3599
- } else {
3600
- itemsByLabel.set(label, item);
3601
- }
3602
- }
3603
- }
3596
+ return (_a = plugin.doComplete) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3604
3597
  })
3605
3598
  );
3606
3599
  if (cancel.isCancellationRequested)
3607
3600
  return;
3608
- if (itemsByLabel.size) {
3609
- return { items: [...itemsByLabel.values()], isIncomplete: true };
3601
+ const itemsByLabel = /* @__PURE__ */ new Map();
3602
+ for (const result of results) {
3603
+ if (result.status !== "fulfilled" || !result.value)
3604
+ continue;
3605
+ for (const item of Array.isArray(result.value) ? result.value : result.value.items) {
3606
+ const { label } = item;
3607
+ const existingItem = itemsByLabel.get(label);
3608
+ if (existingItem) {
3609
+ if ((existingItem.sortText || label) < (item.sortText || label)) {
3610
+ itemsByLabel.set(label, item);
3611
+ }
3612
+ } else {
3613
+ itemsByLabel.set(label, item);
3614
+ }
3615
+ }
3610
3616
  }
3617
+ return { items: [...itemsByLabel.values()], isIncomplete: true };
3611
3618
  },
3612
3619
  async doCompletionResolve(item, cancel) {
3613
3620
  var _a;
@@ -3623,172 +3630,189 @@ var service = {
3623
3630
  }
3624
3631
  },
3625
3632
  async findDefinition(doc, params, cancel) {
3626
- let result;
3627
- await Promise.allSettled(
3628
- plugins.map(async (plugin) => {
3633
+ const results = await Promise.allSettled(
3634
+ plugins.map((plugin) => {
3629
3635
  var _a;
3630
- const cur = await ((_a = plugin.findDefinition) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3631
- if (cancel.isCancellationRequested)
3632
- return;
3633
- if (cur)
3634
- result = (result || []).concat(cur);
3636
+ return (_a = plugin.findDefinition) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3635
3637
  })
3636
3638
  );
3637
3639
  if (cancel.isCancellationRequested)
3638
3640
  return;
3639
- return result;
3641
+ let links;
3642
+ for (const result of results) {
3643
+ if (result.status !== "fulfilled" || !result.value)
3644
+ continue;
3645
+ links = (links || []).concat(result.value);
3646
+ }
3647
+ return links;
3640
3648
  },
3641
3649
  async findReferences(doc, params, cancel) {
3642
- let result;
3643
- await Promise.allSettled(
3644
- plugins.map(async (plugin) => {
3650
+ const results = await Promise.allSettled(
3651
+ plugins.map((plugin) => {
3645
3652
  var _a;
3646
- const cur = await ((_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3647
- if (cancel.isCancellationRequested)
3648
- return;
3649
- if (cur)
3650
- result = (result || []).concat(cur);
3653
+ return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3651
3654
  })
3652
3655
  );
3653
3656
  if (cancel.isCancellationRequested)
3654
3657
  return;
3655
- return result;
3658
+ let references;
3659
+ for (const result of results) {
3660
+ if (result.status !== "fulfilled" || !result.value)
3661
+ continue;
3662
+ references = (references || []).concat(result.value);
3663
+ }
3664
+ return references;
3656
3665
  },
3657
3666
  async findDocumentSymbols(doc, params, cancel) {
3658
- let result;
3659
- await Promise.allSettled(
3660
- plugins.map(async (plugin) => {
3667
+ const results = await Promise.allSettled(
3668
+ plugins.map((plugin) => {
3661
3669
  var _a;
3662
- const cur = await ((_a = plugin.findDocumentSymbols) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3663
- if (cancel.isCancellationRequested)
3664
- return;
3665
- if (cur)
3666
- result = (result || []).concat(cur);
3670
+ return (_a = plugin.findDocumentSymbols) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3667
3671
  })
3668
3672
  );
3669
3673
  if (cancel.isCancellationRequested)
3670
3674
  return;
3671
- return result;
3675
+ let symbols;
3676
+ for (const result of results) {
3677
+ if (result.status !== "fulfilled" || !result.value)
3678
+ continue;
3679
+ symbols = (symbols || []).concat(result.value);
3680
+ }
3681
+ return symbols;
3672
3682
  },
3673
3683
  async findDocumentLinks(doc, params, cancel) {
3674
- let result;
3675
- await Promise.allSettled(
3676
- plugins.map(async (plugin) => {
3684
+ const results = await Promise.allSettled(
3685
+ plugins.map((plugin) => {
3677
3686
  var _a;
3678
- const cur = await ((_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3679
- if (cancel.isCancellationRequested)
3680
- return;
3681
- if (cur)
3682
- result = (result || []).concat(cur);
3687
+ return (_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3683
3688
  })
3684
3689
  );
3685
3690
  if (cancel.isCancellationRequested)
3686
3691
  return;
3687
- return result;
3692
+ let links;
3693
+ for (const result of results) {
3694
+ if (result.status !== "fulfilled" || !result.value)
3695
+ continue;
3696
+ links = (links || []).concat(result.value);
3697
+ }
3698
+ return links;
3688
3699
  },
3689
3700
  async findDocumentHighlights(doc, params, cancel) {
3690
- let result;
3691
- await Promise.allSettled(
3692
- plugins.map(async (plugin) => {
3693
- var _a;
3694
- const cur = await ((_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3695
- if (cancel.isCancellationRequested)
3696
- return;
3697
- if (cur)
3698
- result = (result || []).concat(cur);
3699
- })
3701
+ const results = await Promise.allSettled(
3702
+ plugins.map(
3703
+ (plugin) => {
3704
+ var _a;
3705
+ return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3706
+ }
3707
+ )
3700
3708
  );
3701
3709
  if (cancel.isCancellationRequested)
3702
3710
  return;
3703
- return result;
3711
+ let highlights;
3712
+ for (const result of results) {
3713
+ if (result.status !== "fulfilled" || !result.value)
3714
+ continue;
3715
+ highlights = (highlights || []).concat(result.value);
3716
+ }
3717
+ return highlights;
3704
3718
  },
3705
3719
  async findDocumentColors(doc, params, cancel) {
3706
- let result;
3707
- await Promise.allSettled(
3708
- plugins.map(async (plugin) => {
3720
+ const results = await Promise.allSettled(
3721
+ plugins.map((plugin) => {
3709
3722
  var _a;
3710
- const cur = await ((_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3711
- if (cancel.isCancellationRequested)
3712
- return;
3713
- if (cur)
3714
- result = (result || []).concat(cur);
3723
+ return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3715
3724
  })
3716
3725
  );
3717
3726
  if (cancel.isCancellationRequested)
3718
3727
  return;
3719
- return result;
3728
+ let colors;
3729
+ for (const result of results) {
3730
+ if (result.status !== "fulfilled" || !result.value)
3731
+ continue;
3732
+ colors = (colors || []).concat(result.value);
3733
+ }
3734
+ return colors;
3720
3735
  },
3721
3736
  async getColorPresentations(doc, params, cancel) {
3722
- let result;
3723
- await Promise.allSettled(
3724
- plugins.map(async (plugin) => {
3725
- var _a;
3726
- const cur = await ((_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3727
- if (cancel.isCancellationRequested)
3728
- return;
3729
- if (cur)
3730
- result = (result || []).concat(cur);
3731
- })
3737
+ const results = await Promise.allSettled(
3738
+ plugins.map(
3739
+ (plugin) => {
3740
+ var _a;
3741
+ return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3742
+ }
3743
+ )
3732
3744
  );
3733
3745
  if (cancel.isCancellationRequested)
3734
3746
  return;
3735
- return result;
3747
+ let presentations;
3748
+ for (const result of results) {
3749
+ if (result.status !== "fulfilled" || !result.value)
3750
+ continue;
3751
+ presentations = (presentations || []).concat(result.value);
3752
+ }
3753
+ return presentations;
3736
3754
  },
3737
3755
  async doHover(doc, params, cancel) {
3738
- let result;
3739
- await Promise.allSettled(
3740
- plugins.map(async (plugin) => {
3756
+ const results = await Promise.allSettled(
3757
+ plugins.map((plugin) => {
3741
3758
  var _a;
3742
- const cur = await ((_a = plugin.doHover) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3743
- if (cancel.isCancellationRequested)
3744
- return;
3745
- if (cur) {
3746
- if (result) {
3747
- result.range = maxRange(result.range, cur.range);
3748
- result.contents = mergeHoverContents(result.contents, cur.contents);
3749
- } else {
3750
- result = cur;
3751
- }
3752
- }
3759
+ return (_a = plugin.doHover) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3753
3760
  })
3754
3761
  );
3755
- return result;
3762
+ if (cancel.isCancellationRequested)
3763
+ return;
3764
+ let hovers;
3765
+ for (const result of results) {
3766
+ if (result.status !== "fulfilled" || !result.value)
3767
+ continue;
3768
+ if (hovers) {
3769
+ hovers.range = maxRange(hovers.range, result.value.range);
3770
+ hovers.contents = mergeHoverContents(
3771
+ hovers.contents,
3772
+ result.value.contents
3773
+ );
3774
+ } else {
3775
+ hovers = result.value;
3776
+ }
3777
+ }
3778
+ return hovers;
3756
3779
  },
3757
3780
  async doRename(doc, params, cancel) {
3758
- let changes;
3759
- let changeAnnotations;
3760
- let documentChanges;
3761
- await Promise.allSettled(
3762
- plugins.map(async (plugin) => {
3781
+ const results = await Promise.allSettled(
3782
+ plugins.map((plugin) => {
3763
3783
  var _a;
3764
- const cur = await ((_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3765
- if (cancel.isCancellationRequested)
3766
- return;
3767
- if (cur) {
3768
- if (cur.changes) {
3769
- if (changes) {
3770
- changes = { ...changes };
3771
- for (const uri in cur.changes) {
3772
- changes[uri] = changes[uri] ? changes[uri].concat(cur.changes[uri]) : cur.changes[uri];
3773
- }
3774
- } else {
3775
- changes = cur.changes;
3776
- }
3777
- }
3778
- if (cur.changeAnnotations) {
3779
- changeAnnotations = changeAnnotations ? {
3780
- ...changeAnnotations,
3781
- ...cur.changeAnnotations
3782
- } : cur.changeAnnotations;
3783
- }
3784
- if (cur.documentChanges) {
3785
- documentChanges = documentChanges ? documentChanges.concat(cur.documentChanges) : cur.documentChanges;
3786
- }
3787
- }
3784
+ return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3788
3785
  })
3789
3786
  );
3790
3787
  if (cancel.isCancellationRequested)
3791
3788
  return;
3789
+ let changes;
3790
+ let changeAnnotations;
3791
+ let documentChanges;
3792
+ for (const result of results) {
3793
+ if (result.status !== "fulfilled" || !result.value)
3794
+ continue;
3795
+ const { value } = result;
3796
+ if (value.changes) {
3797
+ if (changes) {
3798
+ changes = { ...changes };
3799
+ for (const uri in value.changes) {
3800
+ changes[uri] = changes[uri] ? changes[uri].concat(value.changes[uri]) : value.changes[uri];
3801
+ }
3802
+ } else {
3803
+ changes = value.changes;
3804
+ }
3805
+ }
3806
+ if (value.changeAnnotations) {
3807
+ changeAnnotations = changeAnnotations ? {
3808
+ ...changeAnnotations,
3809
+ ...value.changeAnnotations
3810
+ } : value.changeAnnotations;
3811
+ }
3812
+ if (value.documentChanges) {
3813
+ documentChanges = documentChanges ? documentChanges.concat(value.documentChanges) : value.documentChanges;
3814
+ }
3815
+ }
3792
3816
  if (changes || changeAnnotations || documentChanges) {
3793
3817
  return {
3794
3818
  changes,
@@ -3798,32 +3822,36 @@ var service = {
3798
3822
  }
3799
3823
  },
3800
3824
  async doCodeActions(doc, params, cancel) {
3801
- let result;
3802
- await Promise.allSettled(
3803
- plugins.map(async (plugin) => {
3825
+ const results = await Promise.allSettled(
3826
+ plugins.map((plugin) => {
3804
3827
  var _a;
3805
- const cur = await ((_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel));
3806
- if (cancel.isCancellationRequested)
3807
- return;
3808
- if (cur)
3809
- result = (result || []).concat(cur);
3828
+ return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
3810
3829
  })
3811
3830
  );
3812
3831
  if (cancel.isCancellationRequested)
3813
3832
  return;
3814
- return result;
3833
+ let actions;
3834
+ for (const result of results) {
3835
+ if (result.status !== "fulfilled" || !result.value)
3836
+ continue;
3837
+ actions = (actions || []).concat(result.value);
3838
+ }
3839
+ return actions;
3815
3840
  },
3816
3841
  async doValidate(doc) {
3817
- let result;
3818
- await Promise.allSettled(
3819
- plugins.map(async (plugin) => {
3842
+ const results = await Promise.allSettled(
3843
+ plugins.map((plugin) => {
3820
3844
  var _a;
3821
- const cur = await ((_a = plugin.doValidate) == null ? void 0 : _a.call(plugin, doc));
3822
- if (cur)
3823
- result = (result || []).concat(cur);
3845
+ return (_a = plugin.doValidate) == null ? void 0 : _a.call(plugin, doc);
3824
3846
  })
3825
3847
  );
3826
- return result;
3848
+ let diagnostics;
3849
+ for (const result of results) {
3850
+ if (result.status !== "fulfilled" || !result.value)
3851
+ continue;
3852
+ diagnostics = (diagnostics || []).concat(result.value);
3853
+ }
3854
+ return diagnostics;
3827
3855
  },
3828
3856
  format: marko_default.format
3829
3857
  };
@@ -4063,7 +4091,7 @@ for (const command in service.commands) {
4063
4091
  }
4064
4092
  function validateDocs() {
4065
4093
  queueDiagnostic();
4066
- Project5.clearCaches();
4094
+ Project6.clearCaches();
4067
4095
  }
4068
4096
  function queueDiagnostic() {
4069
4097
  clearTimeout(diagnosticTimeout);