Skip to content

Commit 604e7f9

Browse files
author
Сосна Евгений
committed
Добавил указание позиции в которой нашли внешний вызов.
1 parent 56cbf6f commit 604e7f9

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

lib/parser.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ SyntaxAnalysis.prototype.AnalyseModule = function (sourceCode, initValueTable, t
227227
{
228228
if( state == stInProc ) Meth.EndLine = i;
229229
state = stInModule;
230+
moduleContext.save(Meth);
230231
}
231232
else if( (Matches = this.RE_VARS_DEF.exec(str)) != null )
232233
{
@@ -271,14 +272,15 @@ SyntaxAnalysis.prototype.AnalyseModule = function (sourceCode, initValueTable, t
271272
if(addToCalls){
272273
if(Meth.Calls.indexOf(Matches[1]) >= 0) continue;
273274
Meth.Calls.push(Matches[1]);
275+
Meth.CallsPosition.push({"call": Matches[1], "line": i, "character": Matches.index});
274276

275277
}
276278

277279
//Сделаем поиск по общим модулям или под документам, вдруг там у нас статический вызов.
278280
//var mdRef = metadata.current.rootObject.childObject("Справочники", "Номенклатура")
279281
}
280282
if( Meth.Calls.indexOf(Matches[1]) >= 0) continue;
281-
Meth.Calls.push(Matches[1]);
283+
Meth.CallsPosition.push({"call": Matches[1], "line": i, "character": Matches.index});
282284
}
283285
}
284286
}
@@ -316,11 +318,10 @@ function _1CModule(sourceText) {
316318
}
317319

318320
/* Возвращает исходный код метода по названию метода. */
319-
_1CModule.prototype.getMethodSource = function(methodName) {
320-
throw ("Not implement");
321+
_1CModule.prototype.getMethod = function(methodName) {
321322
var method = this.context.getMethodByName(methodName);
322323
if (!method) return undefined;
323-
return this.textWindow.Range(method.StartLine + 1, 1, method.EndLine + 1).GetText();
324+
return method;
324325
}
325326

326327
/* Возвращает таблицу значений с описаниями методов модуля. */
@@ -419,19 +420,24 @@ _1CModuleContextDescription.prototype.addMethod = function (method) {
419420
this._methodsByName[method.Name] = method;
420421

421422
// Добавляем метод в таблицу значений.
422-
if (this._vtAllMethods)
423-
{
424-
var methRow = this.NewString();
425-
methRow.name = method.Name;
426-
methRow.isproc = method.IsProc;
427-
methRow.line = method.StartLine;
428-
methRow.endline = method.EndLine;
429-
methRow.context = method.Context;
430-
methRow.isexport = method.IsExport;
431-
methRow.description = method.description;
432-
methRow._method = method;
433-
434-
this._vtAllMethods.insert(methRow);
423+
424+
}
425+
426+
_1CModuleContextDescription.prototype.save = function (method) {
427+
if (this._vtAllMethods) {
428+
if (this._vtAllMethods) {
429+
var methRow = this.NewString();
430+
methRow.name = method.Name;
431+
methRow.isproc = method.IsProc;
432+
methRow.line = method.StartLine;
433+
methRow.endline = method.EndLine;
434+
methRow.context = method.Context;
435+
methRow.isexport = method.IsExport;
436+
methRow.description = method.description;
437+
methRow._method = method;
438+
439+
this._vtAllMethods.insert(methRow);
440+
}
435441
}
436442
}
437443

@@ -475,6 +481,7 @@ function _1CMethodDescription(parentModule) {
475481

476482
// Список вызовов: массив методов, вызываемых из данного метода.
477483
this.Calls = new Array();
484+
this.CallsPosition = new Array();
478485

479486
// Номер строки объявления метода.
480487
this.StartLine = 0;

test/parser_spec.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ describe("Parser", function () {
1414
var parser;
1515
var list;
1616
var names;
17-
var methods;
17+
var methods;
18+
let modulecontext;
1819

1920
beforeEach(function () {
2021
parser = new Parser();
21-
methods = parser.parse(objectFixture).getMethodsTable();
22+
modulecontext = parser.parse(objectFixture);
23+
methods = modulecontext.getMethodsTable();
2224
list = methods.find();
2325
names = _.pluck(list, 'name');
2426
});
@@ -59,10 +61,27 @@ describe("Parser", function () {
5961
it("Функция должна быть иметь 1 вызов _method.Calls", function () {
6062
expect(method._method.Calls.length).to.equal(2);
6163
})
64+
6265
it("Функция должна быть иметь большое описание description", function () {
6366
var text = "dddd"
6467
expect(method.description.split("\n").length).to.equal(12);
68+
});
69+
70+
it("Определим по номеру строки к какой функции она относится", function () {
71+
expect(modulecontext.getMethodByLineNumber(23)).to.be.a('object');
72+
expect(modulecontext.getMethodByLineNumber(23).Name).to.equal("СложнаяФункцияСКучейПараметров");
73+
});
74+
75+
it("Определим по наименованию процедуры старт и начало этой процедуры", function () {
76+
//expect(modulecontext.get)
6577
})
78+
79+
it("Получим список вызовов внешних функций для процедуры ", function () {
80+
expect(modulecontext.getMethodByLineNumber(23)).to.be.a("object");
81+
expect(modulecontext.getMethodByLineNumber(23).Name).to.equal("СложнаяФункцияСКучейПараметров");
82+
})
83+
84+
6685
})
6786

6887
describe("Проверка парсинга комментариев для модуля.", function() {

0 commit comments

Comments
 (0)