@abaplint/cli 2.109.0 → 2.109.1

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 (2) hide show
  1. package/build/cli.js +47 -13
  2. package/package.json +2 -2
package/build/cli.js CHANGED
@@ -3687,18 +3687,22 @@ class ExpandMacros {
3687
3687
  this.globalMacros = globalMacros;
3688
3688
  this.reg = reg;
3689
3689
  }
3690
- find(statements, file) {
3690
+ find(statements, file, clear = true) {
3691
3691
  var _a, _b, _c;
3692
3692
  let nameToken = undefined;
3693
+ let start = undefined;
3693
3694
  let contents = [];
3694
3695
  const macroReferences = (_a = this.reg) === null || _a === void 0 ? void 0 : _a.getMacroReferences();
3695
- macroReferences === null || macroReferences === void 0 ? void 0 : macroReferences.clear(file.getFilename());
3696
+ if (clear) {
3697
+ macroReferences === null || macroReferences === void 0 ? void 0 : macroReferences.clear(file.getFilename());
3698
+ }
3696
3699
  for (let i = 0; i < statements.length; i++) {
3697
3700
  const statement = statements[i];
3698
3701
  const type = statement.get();
3699
3702
  if (type instanceof Statements.Define) {
3700
3703
  // todo, will this break if first token is a pragma?
3701
3704
  nameToken = statement.getTokens()[1];
3705
+ start = statement.getFirstToken().getStart();
3702
3706
  contents = [];
3703
3707
  }
3704
3708
  else if (type instanceof Statements.Include) {
@@ -3710,14 +3714,14 @@ class ExpandMacros {
3710
3714
  const includeMainFile = prog.getMainABAPFile();
3711
3715
  if (includeMainFile) {
3712
3716
  // slow, this copies everything,
3713
- this.find([...includeMainFile.getStatements()], includeMainFile);
3717
+ this.find([...includeMainFile.getStatements()], includeMainFile, false);
3714
3718
  }
3715
3719
  }
3716
3720
  }
3717
3721
  else if (nameToken) {
3718
3722
  if (type instanceof Statements.EndOfDefinition) {
3719
3723
  this.macros.addMacro(nameToken.getStr(), contents, file.getFilename());
3720
- macroReferences === null || macroReferences === void 0 ? void 0 : macroReferences.addDefinition({ filename: file.getFilename(), token: nameToken });
3724
+ macroReferences === null || macroReferences === void 0 ? void 0 : macroReferences.addDefinition({ filename: file.getFilename(), token: nameToken }, start, statement.getLastToken().getEnd());
3721
3725
  nameToken = undefined;
3722
3726
  }
3723
3727
  else if (!(type instanceof _statement_1.Comment)) {
@@ -42861,6 +42865,7 @@ const LServer = __webpack_require__(/*! vscode-languageserver-types */ "./node_m
42861
42865
  const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "./node_modules/@abaplint/core/build/src/objects/_abap_object.js");
42862
42866
  const _lsp_utils_1 = __webpack_require__(/*! ./_lsp_utils */ "./node_modules/@abaplint/core/build/src/lsp/_lsp_utils.js");
42863
42867
  const _lookup_1 = __webpack_require__(/*! ./_lookup */ "./node_modules/@abaplint/core/build/src/lsp/_lookup.js");
42868
+ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "./node_modules/@abaplint/core/build/src/abap/2_statements/statements/_statement.js");
42864
42869
  class Hover {
42865
42870
  constructor(reg) {
42866
42871
  this.reg = reg;
@@ -42884,6 +42889,9 @@ class Hover {
42884
42889
  || found.token instanceof Tokens.StringTemplateMiddle) {
42885
42890
  return { kind: LServer.MarkupKind.Markdown, value: "String Template" };
42886
42891
  }
42892
+ else if (found.snode.get() instanceof _statement_1.MacroCall) {
42893
+ return { kind: LServer.MarkupKind.Markdown, value: "Macro Call" };
42894
+ }
42887
42895
  else if (found.snode.get() instanceof Statements.Define && found.stack.length === 2) {
42888
42896
  return { kind: LServer.MarkupKind.Markdown, value: "Macro Name" };
42889
42897
  }
@@ -43723,11 +43731,22 @@ class MacroReferences {
43723
43731
  this.definitions = {};
43724
43732
  this.references = {};
43725
43733
  }
43726
- addDefinition(ref) {
43734
+ addDefinition(ref, start, end) {
43727
43735
  if (this.definitions[ref.filename] === undefined) {
43728
43736
  this.definitions[ref.filename] = [];
43729
43737
  }
43730
- this.definitions[ref.filename].push(ref);
43738
+ else if (this.definitions[ref.filename].find((d) => d.token.getStart().equals(ref.token.getStart()))) {
43739
+ return;
43740
+ }
43741
+ this.definitions[ref.filename].push({ token: ref.token, start, end });
43742
+ }
43743
+ getDefinitionPosition(filename, token) {
43744
+ for (const d of this.definitions[filename] || []) {
43745
+ if (d.token.getStart().equals(token.getStart())) {
43746
+ return { start: d.token.getStart(), end: d.token.getEnd() };
43747
+ }
43748
+ }
43749
+ return undefined;
43731
43750
  }
43732
43751
  addReference(ref) {
43733
43752
  if (this.references[ref.filename] === undefined) {
@@ -43736,7 +43755,11 @@ class MacroReferences {
43736
43755
  this.references[ref.filename].push(ref);
43737
43756
  }
43738
43757
  listDefinitionsByFile(filename) {
43739
- return this.definitions[filename] || [];
43758
+ const ret = [];
43759
+ for (const d of this.definitions[filename] || []) {
43760
+ ret.push(d.token);
43761
+ }
43762
+ return ret;
43740
43763
  }
43741
43764
  listUsagesbyMacro(filename, token) {
43742
43765
  const ret = [];
@@ -51722,7 +51745,7 @@ class Registry {
51722
51745
  }
51723
51746
  static abaplintVersion() {
51724
51747
  // magic, see build script "version.sh"
51725
- return "2.109.0";
51748
+ return "2.109.1";
51726
51749
  }
51727
51750
  getDDICReferences() {
51728
51751
  return this.ddicReferences;
@@ -72357,6 +72380,7 @@ const issue_1 = __webpack_require__(/*! ../issue */ "./node_modules/@abaplint/co
72357
72380
  const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "./node_modules/@abaplint/core/build/src/rules/_basic_rule_config.js");
72358
72381
  const _irule_1 = __webpack_require__(/*! ./_irule */ "./node_modules/@abaplint/core/build/src/rules/_irule.js");
72359
72382
  const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "./node_modules/@abaplint/core/build/src/objects/_abap_object.js");
72383
+ const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "./node_modules/@abaplint/core/build/src/edit_helper.js");
72360
72384
  class UnusedMacrosConf extends _basic_rule_config_1.BasicRuleConfig {
72361
72385
  constructor() {
72362
72386
  super(...arguments);
@@ -72377,6 +72401,14 @@ class UnusedMacros {
72377
72401
  title: "Unused macros",
72378
72402
  shortDescription: `Checks for unused macro definitions definitions`,
72379
72403
  tags: [_irule_1.RuleTag.Quickfix],
72404
+ badExample: `DEFINE foobar1.
72405
+ WRITE 'hello'.
72406
+ END-OF-DEFINITION.`,
72407
+ goodExample: `DEFINE foobar2.
72408
+ WRITE 'hello'.
72409
+ END-OF-DEFINITION.
72410
+
72411
+ foobar2.`,
72380
72412
  };
72381
72413
  }
72382
72414
  getConfig() {
@@ -72400,11 +72432,13 @@ class UnusedMacros {
72400
72432
  }
72401
72433
  const references = this.reg.getMacroReferences();
72402
72434
  for (const file of obj.getABAPFiles()) {
72403
- for (const macro of references.listDefinitionsByFile(file.getFilename())) {
72404
- const usages = references.listUsagesbyMacro(file.getFilename(), macro.token);
72405
- if (usages.length === 0 && ((_a = this.conf.skipNames) === null || _a === void 0 ? void 0 : _a.includes(macro.token.getStr().toUpperCase())) === false) {
72406
- const message = "Unused macro definition: " + macro.token.getStr();
72407
- result.push(issue_1.Issue.atToken(file, macro.token, message, this.getMetadata().key, this.conf.severity));
72435
+ for (const macroToken of references.listDefinitionsByFile(file.getFilename())) {
72436
+ const usages = references.listUsagesbyMacro(file.getFilename(), macroToken);
72437
+ if (usages.length === 0 && ((_a = this.conf.skipNames) === null || _a === void 0 ? void 0 : _a.includes(macroToken.getStr().toUpperCase())) === false) {
72438
+ const message = "Unused macro definition: " + macroToken.getStr();
72439
+ const pos = references.getDefinitionPosition(file.getFilename(), macroToken);
72440
+ const fix = edit_helper_1.EditHelper.deleteRange(file, pos.start, pos.end);
72441
+ result.push(issue_1.Issue.atToken(file, macroToken, message, this.getMetadata().key, this.conf.severity, fix));
72408
72442
  }
72409
72443
  }
72410
72444
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/cli",
3
- "version": "2.109.0",
3
+ "version": "2.109.1",
4
4
  "description": "abaplint - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "homepage": "https://abaplint.org",
40
40
  "devDependencies": {
41
- "@abaplint/core": "^2.109.0",
41
+ "@abaplint/core": "^2.109.1",
42
42
  "@types/chai": "^4.3.16",
43
43
  "@types/glob": "^8.1.0",
44
44
  "@types/minimist": "^1.2.5",