@abaplint/core 2.101.11 → 2.101.13

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.
@@ -1063,6 +1063,10 @@ declare class CloseDataset implements IStatement {
1063
1063
  getMatcher(): IStatementRunnable;
1064
1064
  }
1065
1065
 
1066
+ declare type CodeLensSettings = {
1067
+ messageText: boolean;
1068
+ };
1069
+
1066
1070
  declare class Collect implements IStatement {
1067
1071
  getMatcher(): IStatementRunnable;
1068
1072
  }
@@ -3272,6 +3276,10 @@ declare class Initialization implements IStatement {
3272
3276
  getMatcher(): IStatementRunnable;
3273
3277
  }
3274
3278
 
3279
+ declare type InlayHintsSettings = {
3280
+ inferredTypes: boolean;
3281
+ };
3282
+
3275
3283
  declare class InlineData extends Expression {
3276
3284
  getRunnable(): IStatementRunnable;
3277
3285
  }
@@ -3787,7 +3795,8 @@ export declare class LanguageServer {
3787
3795
  references(params: ITextDocumentPositionParams): LServer.Location[];
3788
3796
  static semanticTokensLegend(): LServer.SemanticTokensLegend;
3789
3797
  semanticTokensRange(range: ITextDocumentRange): LServer.SemanticTokens;
3790
- codeLens(textDocument: LServer.TextDocumentIdentifier): LServer.CodeLens[];
3798
+ codeLens(textDocument: LServer.TextDocumentIdentifier, settings?: CodeLensSettings): LServer.CodeLens[];
3799
+ inlayHints(textDocument: LServer.TextDocumentIdentifier, settings?: InlayHintsSettings): LServer.InlayHint[];
3791
3800
  help(textDocument: LServer.TextDocumentIdentifier, position: LServer.Position): string;
3792
3801
  listDefinitionPositions(textDocument: LServer.TextDocumentIdentifier): LServer.Range[];
3793
3802
  listReadPositions(textDocument: LServer.TextDocumentIdentifier): LServer.Range[];
@@ -14,7 +14,7 @@ class ReadTable {
14
14
  const from = (0, combi_1.seq)("FROM", expressions_1.Source);
15
15
  const fields = (0, combi_1.plus)((0, combi_1.alt)((0, combi_1.seq)("INTO", (0, combi_1.failStar)()), expressions_1.FieldSub));
16
16
  const perm = (0, combi_1.per)((0, combi_1.alt)(index, key, from), expressions_1.ReadTableTarget, using, comparing, "CASTING", "TRANSPORTING ALL FIELDS", (0, combi_1.seq)("TRANSPORTING", (0, combi_1.altPrio)(expressions_1.Dynamic, fields)), "BINARY SEARCH");
17
- return (0, combi_1.seq)("READ TABLE", (0, combi_1.alt)((0, combi_1.ver)(version_1.Version.v740sp02, expressions_1.Source), expressions_1.SimpleSource2), (0, combi_1.opt)(perm));
17
+ return (0, combi_1.seq)("READ TABLE", (0, combi_1.alt)(expressions_1.SimpleSource2, (0, combi_1.ver)(version_1.Version.v740sp02, expressions_1.Source)), (0, combi_1.opt)(perm));
18
18
  }
19
19
  }
20
20
  exports.ReadTable = ReadTable;
@@ -1173,7 +1173,7 @@ BuiltIn.methods = [
1173
1173
  {
1174
1174
  name: "XSTRLEN",
1175
1175
  mandatory: {
1176
- "val": new basic_1.XStringType(),
1176
+ "val": new basic_1.XSequenceType(),
1177
1177
  },
1178
1178
  return: new basic_1.IntegerType(),
1179
1179
  },
@@ -209,7 +209,7 @@ class TypeUtils {
209
209
  return false;
210
210
  }
211
211
  isAssignableStrict(source, target) {
212
- var _a, _b, _c, _d, _e;
212
+ var _a, _b, _c, _d, _e, _f;
213
213
  /*
214
214
  console.dir(source);
215
215
  console.dir(target);
@@ -248,8 +248,14 @@ class TypeUtils {
248
248
  return false;
249
249
  }
250
250
  }
251
- else if (source instanceof basic_1.StringType && target instanceof basic_1.StructureType) {
252
- if (this.structureContainsString(target)) {
251
+ else if (source instanceof basic_1.StringType) {
252
+ if (target instanceof basic_1.StructureType && this.structureContainsString(target)) {
253
+ return false;
254
+ }
255
+ else if (target instanceof basic_1.XSequenceType) {
256
+ if (((_f = source.getAbstractTypeData()) === null || _f === void 0 ? void 0 : _f.derivedFromConstant) === true) {
257
+ return true;
258
+ }
253
259
  return false;
254
260
  }
255
261
  return true;
@@ -272,6 +278,11 @@ class TypeUtils {
272
278
  return false;
273
279
  }
274
280
  }
281
+ else if (source instanceof basic_1.XStringType) {
282
+ if (target instanceof basic_1.CLikeType) {
283
+ return false;
284
+ }
285
+ }
275
286
  return this.isAssignable(source, target);
276
287
  }
277
288
  isAssignable(source, target) {
@@ -15,6 +15,9 @@ class Constant {
15
15
  }
16
16
  return new basic_1.CharacterType(len, { derivedFromConstant: true });
17
17
  }
18
+ else if (node.getFirstToken().getStr().startsWith("`")) {
19
+ return new basic_1.StringType({ qualifiedName: "STRING", derivedFromConstant: true });
20
+ }
18
21
  else {
19
22
  return new basic_1.StringType({ qualifiedName: "STRING" });
20
23
  }
@@ -65,27 +65,36 @@ class Source {
65
65
  {
66
66
  const foundType = this.determineType(node, scope, filename, targetType);
67
67
  const bodyType = new reduce_body_1.ReduceBody().runSyntax(node.findDirectExpression(Expressions.ReduceBody), scope, filename, foundType);
68
- if (foundType === undefined || foundType.isGeneric() === true) {
68
+ if (foundType === undefined || foundType.isGeneric()) {
69
69
  this.addIfInferred(node, scope, filename, bodyType);
70
70
  }
71
+ else {
72
+ this.addIfInferred(node, scope, filename, foundType);
73
+ }
71
74
  return foundType ? foundType : bodyType;
72
75
  }
73
76
  case "SWITCH":
74
77
  {
75
78
  const foundType = this.determineType(node, scope, filename, targetType);
76
79
  const bodyType = new switch_body_1.SwitchBody().runSyntax(node.findDirectExpression(Expressions.SwitchBody), scope, filename);
77
- if (foundType === undefined || foundType.isGeneric() === true) {
80
+ if (foundType === undefined || foundType.isGeneric()) {
78
81
  this.addIfInferred(node, scope, filename, bodyType);
79
82
  }
83
+ else {
84
+ this.addIfInferred(node, scope, filename, foundType);
85
+ }
80
86
  return foundType ? foundType : bodyType;
81
87
  }
82
88
  case "COND":
83
89
  {
84
90
  const foundType = this.determineType(node, scope, filename, targetType);
85
91
  const bodyType = new cond_body_1.CondBody().runSyntax(node.findDirectExpression(Expressions.CondBody), scope, filename);
86
- if (foundType === undefined || foundType.isGeneric() === true) {
92
+ if (foundType === undefined || foundType.isGeneric()) {
87
93
  this.addIfInferred(node, scope, filename, bodyType);
88
94
  }
95
+ else {
96
+ this.addIfInferred(node, scope, filename, foundType);
97
+ }
89
98
  return foundType ? foundType : bodyType;
90
99
  }
91
100
  case "CONV":
@@ -222,10 +231,12 @@ class Source {
222
231
  throw new Error("determineType, child TypeNameOrInfer not found");
223
232
  }
224
233
  else if (typeName === "#" && targetType) {
225
- const found = basic.lookupQualifiedName(targetType.getQualifiedName());
234
+ // const found = basic.lookupQualifiedName(targetType.getQualifiedName());
235
+ /*
226
236
  if (found) {
227
- scope.addReference(typeToken, found, _reference_1.ReferenceType.InferredType, filename);
237
+ scope.addReference(typeToken, found, ReferenceType.InferredType, filename);
228
238
  }
239
+ */
229
240
  return targetType;
230
241
  }
231
242
  if (typeName !== "#" && typeToken) {
@@ -6,10 +6,15 @@ const source_1 = require("../expressions/source");
6
6
  const target_1 = require("../expressions/target");
7
7
  const basic_1 = require("../../types/basic");
8
8
  const inline_data_1 = require("../expressions/inline_data");
9
+ const _type_utils_1 = require("../_type_utils");
9
10
  class GetBit {
10
11
  runSyntax(node, scope, filename) {
12
+ let lastType = undefined;
11
13
  for (const s of node.findDirectExpressions(Expressions.Source)) {
12
- new source_1.Source().runSyntax(s, scope, filename);
14
+ lastType = new source_1.Source().runSyntax(s, scope, filename);
15
+ }
16
+ if (lastType && new _type_utils_1.TypeUtils(scope).isHexLike(lastType) === false) {
17
+ throw new Error("Input must be byte-like");
13
18
  }
14
19
  for (const t of node.findDirectExpressions(Expressions.Target)) {
15
20
  const inline = t === null || t === void 0 ? void 0 : t.findDirectExpression(Expressions.InlineData);
@@ -4,13 +4,17 @@ exports.SetBit = void 0;
4
4
  const Expressions = require("../../2_statements/expressions");
5
5
  const source_1 = require("../expressions/source");
6
6
  const target_1 = require("../expressions/target");
7
+ const _type_utils_1 = require("../_type_utils");
7
8
  class SetBit {
8
9
  runSyntax(node, scope, filename) {
9
10
  for (const s of node.findDirectExpressions(Expressions.Source)) {
10
11
  new source_1.Source().runSyntax(s, scope, filename);
11
12
  }
12
13
  for (const t of node.findDirectExpressions(Expressions.Target)) {
13
- new target_1.Target().runSyntax(t, scope, filename);
14
+ const typ = new target_1.Target().runSyntax(t, scope, filename);
15
+ if (typ && new _type_utils_1.TypeUtils(scope).isHexLike(typ) === false) {
16
+ throw new Error("Input must be byte-like");
17
+ }
14
18
  }
15
19
  }
16
20
  }
@@ -26,6 +26,9 @@ class LSPUtils {
26
26
  static tokenToRange(token) {
27
27
  return LServer.Range.create(token.getStart().getRow() - 1, token.getStart().getCol() - 1, token.getEnd().getRow() - 1, token.getEnd().getCol() - 1);
28
28
  }
29
+ static positionToLS(pos) {
30
+ return LServer.Position.create(pos.getRow() - 1, pos.getCol() - 1);
31
+ }
29
32
  static identiferToLocation(identifier) {
30
33
  return {
31
34
  uri: identifier.getFilename(),
@@ -9,7 +9,7 @@ class CodeLens {
9
9
  constructor(reg) {
10
10
  this.reg = reg;
11
11
  }
12
- list(textDocument) {
12
+ list(textDocument, settings = { messageText: true }) {
13
13
  var _a;
14
14
  const file = _lsp_utils_1.LSPUtils.getABAPFile(this.reg, textDocument.uri);
15
15
  if (file === undefined) {
@@ -21,14 +21,22 @@ class CodeLens {
21
21
  }
22
22
  new syntax_1.SyntaxLogic(this.reg, obj).run();
23
23
  const ret = [];
24
- const list = this.reg.getMSAGReferences().listByFilename(file.getFilename());
25
- for (const l of list) {
26
- const msag = this.reg.getObject("MSAG", l.messageClass);
27
- if (msag === undefined) {
28
- continue;
24
+ if (settings.messageText === true) {
25
+ const list = this.reg.getMSAGReferences().listByFilename(file.getFilename());
26
+ for (const l of list) {
27
+ const msag = this.reg.getObject("MSAG", l.messageClass);
28
+ if (msag === undefined) {
29
+ continue;
30
+ }
31
+ const text = (_a = msag.getByNumber(l.number)) === null || _a === void 0 ? void 0 : _a.getMessage();
32
+ if (text === undefined) {
33
+ continue;
34
+ }
35
+ ret.push({
36
+ range: _lsp_utils_1.LSPUtils.tokenToRange(l.token),
37
+ command: LServer.Command.create(text, ""),
38
+ });
29
39
  }
30
- const text = (_a = msag.getByNumber(l.number)) === null || _a === void 0 ? void 0 : _a.getMessage();
31
- ret.push(LServer.CodeLens.create(_lsp_utils_1.LSPUtils.tokenToRange(l.token), text));
32
40
  }
33
41
  return ret;
34
42
  }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InlayHints = void 0;
4
+ const LServer = require("vscode-languageserver-types");
5
+ const _lsp_utils_1 = require("./_lsp_utils");
6
+ const syntax_1 = require("../abap/5_syntax/syntax");
7
+ const _abap_object_1 = require("../objects/_abap_object");
8
+ const _reference_1 = require("../abap/5_syntax/_reference");
9
+ const _typed_identifier_1 = require("../abap/types/_typed_identifier");
10
+ const types_1 = require("../abap/types");
11
+ class InlayHints {
12
+ constructor(reg) {
13
+ this.reg = reg;
14
+ }
15
+ list(textDocument, settings = { inferredTypes: true }) {
16
+ const file = _lsp_utils_1.LSPUtils.getABAPFile(this.reg, textDocument.uri);
17
+ if (file === undefined) {
18
+ return [];
19
+ }
20
+ const obj = this.reg.findObjectForFile(file);
21
+ if (obj === undefined || !(obj instanceof _abap_object_1.ABAPObject)) {
22
+ return [];
23
+ }
24
+ const top = new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop();
25
+ const ret = [];
26
+ if (settings.inferredTypes === true) {
27
+ const implicit = this.findImplicitReferences(top);
28
+ for (const i of implicit) {
29
+ let label = undefined;
30
+ if (i.resolved instanceof _typed_identifier_1.TypedIdentifier) {
31
+ label = "TYPE " + i.resolved.getType().toABAP();
32
+ }
33
+ else if (i.resolved instanceof types_1.ClassDefinition) {
34
+ label = "TYPE REF TO " + i.resolved.getName();
35
+ }
36
+ if (label === undefined) {
37
+ continue;
38
+ }
39
+ ret.push({
40
+ label: label,
41
+ tooltip: "Inferred type",
42
+ kind: LServer.InlayHintKind.Type,
43
+ paddingLeft: true,
44
+ paddingRight: true,
45
+ position: _lsp_utils_1.LSPUtils.positionToLS(i.position.getEnd()),
46
+ });
47
+ }
48
+ }
49
+ return ret;
50
+ }
51
+ findImplicitReferences(node) {
52
+ const ret = [];
53
+ for (const r of node.getData().references) {
54
+ if (r.referenceType === _reference_1.ReferenceType.InferredType) {
55
+ ret.push(r);
56
+ }
57
+ }
58
+ for (const c of node.getChildren()) {
59
+ ret.push(...this.findImplicitReferences(c));
60
+ }
61
+ return ret;
62
+ }
63
+ }
64
+ exports.InlayHints = InlayHints;
65
+ //# sourceMappingURL=inlay_hints.js.map
@@ -17,6 +17,7 @@ const implementation_1 = require("./implementation");
17
17
  const semantic_1 = require("./semantic");
18
18
  const statement_flow_1 = require("../abap/flow/statement_flow");
19
19
  const code_lens_1 = require("./code_lens");
20
+ const inlay_hints_1 = require("./inlay_hints");
20
21
  // note Ranges are zero based in LSP,
21
22
  // https://github.com/microsoft/language-server-protocol/blob/main/versions/protocol-2-x.md#range
22
23
  // but 1 based in abaplint
@@ -98,8 +99,12 @@ class LanguageServer {
98
99
  return new semantic_1.SemanticHighlighting(this.reg).semanticTokensRange(range);
99
100
  }
100
101
  // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeLens
101
- codeLens(textDocument) {
102
- return new code_lens_1.CodeLens(this.reg).list(textDocument);
102
+ codeLens(textDocument, settings) {
103
+ return new code_lens_1.CodeLens(this.reg).list(textDocument, settings);
104
+ }
105
+ // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
106
+ inlayHints(textDocument, settings) {
107
+ return new inlay_hints_1.InlayHints(this.reg).list(textDocument, settings);
103
108
  }
104
109
  ////////////////////////////////////////
105
110
  // ______ _
@@ -65,7 +65,7 @@ class Registry {
65
65
  }
66
66
  static abaplintVersion() {
67
67
  // magic, see build script "version.sh"
68
- return "2.101.11";
68
+ return "2.101.13";
69
69
  }
70
70
  getDDICReferences() {
71
71
  return this.ddicReferences;
@@ -510,6 +510,10 @@ Make sure to test the downported code, it might not always be completely correct
510
510
  if (found) {
511
511
  return found;
512
512
  }
513
+ found = this.downportReadTable(high, lowFile, highSyntax);
514
+ if (found) {
515
+ return found;
516
+ }
513
517
  return undefined;
514
518
  }
515
519
  //////////////////////////////////////////
@@ -805,6 +809,22 @@ ${indentation}${uniqueName} = ${source.concatTokens()}.\n${indentation}`);
805
809
  }
806
810
  return undefined;
807
811
  }
812
+ downportReadTable(high, lowFile, highSyntax) {
813
+ if (!(high.get() instanceof Statements.ReadTable)) {
814
+ return undefined;
815
+ }
816
+ const source = high.findExpressionAfterToken("TABLE");
817
+ if ((source === null || source === void 0 ? void 0 : source.get()) instanceof Expressions.Source) {
818
+ const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
819
+ const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
820
+ const firstToken = high.getFirstToken();
821
+ const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, firstToken.getStart(), `DATA(${uniqueName}) = ${source.concatTokens()}.\n` + indentation);
822
+ const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, source.getFirstToken().getStart(), source.getLastToken().getEnd(), uniqueName);
823
+ const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
824
+ return issue_1.Issue.atToken(lowFile, high.getFirstToken(), "Outline table source", this.getMetadata().key, this.conf.severity, fix);
825
+ }
826
+ return undefined;
827
+ }
808
828
  replaceInsertExpression(high, lowFile, highSyntax) {
809
829
  if (!(high.get() instanceof Statements.InsertInternal)) {
810
830
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.101.11",
3
+ "version": "2.101.13",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",
@@ -53,7 +53,7 @@
53
53
  "@types/mocha": "^10.0.1",
54
54
  "@types/node": "^20.2.5",
55
55
  "chai": "^4.3.7",
56
- "eslint": "^8.41.0",
56
+ "eslint": "^8.42.0",
57
57
  "mocha": "^10.2.0",
58
58
  "c8": "^7.14.0",
59
59
  "source-map-support": "^0.5.21",
@@ -61,7 +61,7 @@
61
61
  "typescript": "^5.1.3"
62
62
  },
63
63
  "dependencies": {
64
- "fast-xml-parser": "^4.2.2",
64
+ "fast-xml-parser": "^4.2.3",
65
65
  "json5": "^2.2.3",
66
66
  "vscode-languageserver-types": "^3.17.3"
67
67
  }