public void GetMethodCallWithNewlines()
        {
            var test = @"func void Ninja_ManaReg_ApplyINI() {
	
	var string ini_threshold; ini_threshold = MEM_GetGothOpt(NINJA_MANAREG_INI, NINJA_MANAREG_INI_THRESHOLD);
	var string ini_divisor; ini_divisor = MEM_GetGothOpt(NINJA_MANAREG_INI, NINJA_MANAREG_INI_DIVISOR);

	Ninja_ManaReg_Mana_Threshold = DEFAULT_NINJA_MANAREG_MANA_THRESHOLD;
	Ninja_ManaReg_Max_Mana_Divisor = DEFAULT_NINJA_MANAREG_MAX_MANA_DIVISOR;
	
	MEM_Info(
		ConcatStrings(
			ConcatStrings(NINJA_MANAREG_VERSION, // Some comments
			"": THRESHOLD FROM INI = ""), ini_threshold));
	MEM_Info(ConcatStrings(ConcatStrings(NINJA_MANAREG_VERSION, "": DIVISOR FROM INI = ""), ini_divisor));
	
	if (!Hlp_StrCmp(ini_threshold, """")) {
		Ninja_ManaReg_Mana_Threshold = STR_ToInt(ini_threshold);
	};
	
	
	if (!Hlp_StrCmp(ini_divisor, """")) {
		Ninja_ManaReg_Max_Mana_Divisor = STR_ToInt(ini_divisor);
	};
};";
            var line = 11; var column = 15;
            var doc = new BufferedDocument(test.ToCharArray());
            var mc  = doc.GetMethodCall(new OmniSharp.Extensions.LanguageServer.Protocol.Models.Position(line, column));

            Assert.AreEqual(@"ConcatStrings(NINJA_MANAREG_VERSION, // Some comments
			"": THRESHOLD"            , mc);
        }
        public void GetMethodCall()
        {
            var test = @"const string NINJA_MANAREG_VERSION = ""ManaReg 1.1.0"";
func void Ninja_ManaReg_Regeneration() {
    // Not during loading
    if (!Hlp_IsValidNpc(hero)) { return; };
    // Only in-game
    if (!MEM_Game.timestep) { return; };
    // Only in a certain interval
    var int delayTimer; delayTimer += MEM_Timer.frameTime;
    if (delayTimer < DEFAULT_NINJA_MANAREG_TICKRATE) { return; };
	
    delayTimer -= DEFAULT_NINJA_MANAREG_TICKRATE;
    
    if (hero.attribute[ATR_MANA_MAX] >= Ninja_ManaReg_Mana_Threshold) {
        if (hero.attribute[ATR_MANA] < hero.attribute[ATR_MANA_MAX]) {
            var int menge; menge = (hero.attribute[ATR_MANA_MAX] + (Ninja_ManaReg_Max_Mana_Divisor/2)) / Ninja_ManaReg_Max_Mana_Divisor;
            Npc_ChangeAttribute(hero, ATR_MANA, menge);
		};
    };
};";
            var line = 15; var column = 32;
            var doc = new BufferedDocument(test.ToCharArray());
            var mc  = doc.GetMethodCall(new OmniSharp.Extensions.LanguageServer.Protocol.Models.Position(line, column));

            Assert.AreEqual("Npc_ChangeAttribute(", mc);

            column = 47;
            mc     = doc.GetMethodCall(new OmniSharp.Extensions.LanguageServer.Protocol.Models.Position(line, column));
            Assert.AreEqual("Npc_ChangeAttribute(hero, ATR_MANA,", mc);
        }
        public Task <SignatureHelp> Handle(SignatureHelpParams request, CancellationToken cancellationToken)
        {
            var doc = bufferManager.GetBuffer(request.TextDocument.Uri.AbsolutePath);

            if (doc == null)
            {
                return(null);
            }

            var line = doc.GetMethodCall(request.Position).Trim();

            if (rxFuncDef.IsMatch(line))
            {
                return(null);
            }

            var contextLine = line;

            contextLine = rxStringValues.Replace(contextLine, "");

            var oldLen = -1;

            while (contextLine.Length != oldLen)
            {
                oldLen      = contextLine.Length;
                contextLine = rxFuncCall.Replace(contextLine, "");
            }

            var idxOfParen = contextLine.LastIndexOf('(');

            if (idxOfParen < 0)
            {
                return(NullSignatureHelp);
            }

            string word = null;

            for (var i = idxOfParen - 1; i > 0; i--)
            {
                var c = contextLine[i];
                if (!BufferedDocument.IsIdentifier(c))
                {
                    var start = i + 1;
                    word = contextLine.Substring(start, idxOfParen - start);
                    break;
                }
            }
            if (word == null)
            {
                word = contextLine.Substring(0, idxOfParen);
            }
            word = word.Trim();
            var sigCtx = contextLine.Substring(idxOfParen + 1);
            var func   = (Function)documentsManager.GetGlobalSymbols()
                         .FirstOrDefault(x => x is Function && x.Name.Equals(word, StringComparison.OrdinalIgnoreCase));

            if (func != null)
            {
                var signatureHelp = new SignatureHelp
                {
                    Signatures = new Container <SignatureInformation>(new SignatureInformation
                    {
                        Label      = func.ToString(),
                        Parameters = new Container <ParameterInformation>(func.Parameters.Select(x => new ParameterInformation
                        {
                            Label = x.ToString(),
                        })),
                        Documentation = func.Documentation,
                    }),
                    ActiveParameter = sigCtx.Count(x => x == ','),
                    ActiveSignature = 0
                };
                return(Task.FromResult(signatureHelp));
            }
            return(NullSignatureHelp);
        }