public (List <RhetosSignature> signatures, int?activeSignature, int?activeParameter) GetSignatureHelpAtPosition(LineChr lineChr)
        {
            var analysis = GetAnalysis(lineChr);

            if (analysis.KeywordToken == null || analysis.IsAfterAnyErrorLine(lineChr))
            {
                return(null, null, null);
            }

            var signaturesWithDocumentation = conceptQueries.GetSignaturesWithDocumentation(analysis.KeywordToken.Value);
            var validConcepts = analysis.GetValidConceptsWithActiveParameter();

            if (!validConcepts.Any())
            {
                return(signaturesWithDocumentation, null, null);
            }

            var sortedConcepts = validConcepts
                                 .Select(valid =>
                                         (
                                             valid.conceptType,
                                             valid.activeParamater,
                                             parameterCount: ConceptInfoType.GetParameters(valid.conceptType).Count,
                                             documentation: signaturesWithDocumentation.Single(sig => sig.ConceptInfoType == valid.conceptType)
                                         ))
                                 .OrderBy(valid => valid.activeParamater >= valid.parameterCount)
                                 .ThenBy(valid => valid.parameterCount)
                                 .ThenBy(valid => valid.conceptType.Name)
                                 .ToList();

            var activeParameter = sortedConcepts.First().activeParamater;

            return(sortedConcepts.Select(sorted => sorted.documentation).ToList(), 0, activeParameter);
        }
        private RhetosSignature CreateRhetosSignature(Type conceptInfoType)
        {
            var prefix = "    ";

            var signature        = ConceptInfoType.SignatureDescription(conceptInfoType);
            var documentation    = $"{prefix}* defined by {conceptInfoType.FullName}";
            var xmlDocumentation = xmlDocumentationProvider.GetDocumentation(conceptInfoType, prefix);

            if (!string.IsNullOrEmpty(xmlDocumentation))
            {
                documentation = $"{xmlDocumentation}\n{documentation}";
            }

            return(new RhetosSignature()
            {
                ConceptInfoType = conceptInfoType,
                Parameters = ConceptInfoType.GetParameters(conceptInfoType),
                Signature = signature,
                Documentation = documentation
            });
        }
Exemplo n.º 3
0
        private int GetActiveParameterForValidConcept(Type conceptType)
        {
            var activeParameter = 0;

            // we have parsed some members successfully for this concept type
            if (LastTokenParsed.ContainsKey(conceptType))
            {
                activeParameter = ConceptInfoType.IndexOfParameter(conceptType, LastMemberReadAttempt[conceptType]);

                // if we have just typed a keyword OR have stopped typing a parameter (by pressing space, etc.), we need to advance to next parameter
                // keyword scenario is possible in nested concepts, where we already have valid parameters and are just typing a keyword
                var lineChr      = new LineChr(Line, Chr);
                var atLastParsed = GetTokenAtPosition(lineChr) == LastTokenParsed[conceptType] || GetTokenLeftOfPosition(lineChr) == LastTokenParsed[conceptType];
                var atKeyword    = string.Equals(ConceptInfoHelper.GetKeyword(conceptType), LastTokenParsed[conceptType].Value, StringComparison.InvariantCultureIgnoreCase);
                if (atKeyword || !atLastParsed)
                {
                    activeParameter++;
                }
            }

            return(activeParameter);
        }
Exemplo n.º 4
0
        public override Task <SignatureHelp> Handle(SignatureHelpParams request, CancellationToken cancellationToken)
        {
            log.LogDebug($"SignatureHelp requested at {request.Position.ToLineChr()}.");
            var rhetosDocument = rhetosWorkspace.GetRhetosDocument(request.TextDocument.Uri);

            if (rhetosDocument == null)
            {
                return(Task.FromResult <SignatureHelp>(null));
            }

            var signatures = rhetosDocument.GetSignatureHelpAtPosition(request.Position.ToLineChr());

            if (signatures.signatures == null)
            {
                return(Task.FromResult <SignatureHelp>(null));
            }

            ParameterInformation FromRhetosParameter(ConceptMember conceptMember) => new ParameterInformation()
            {
                Documentation = "",
                Label         = new ParameterInformationLabel(ConceptInfoType.ConceptMemberDescription(conceptMember))
            };

            SignatureInformation FromRhetosSignature(RhetosSignature rhetosSignature) => new SignatureInformation()
            {
                Documentation = rhetosSignature.Documentation,
                Label         = rhetosSignature.Signature,
                Parameters    = new Container <ParameterInformation>(rhetosSignature.Parameters.Select(FromRhetosParameter))
            };

            var signatureHelp = new SignatureHelp()
            {
                Signatures      = new Container <SignatureInformation>(signatures.signatures.Select(FromRhetosSignature)),
                ActiveSignature = signatures.activeSignature ?? 100,
                ActiveParameter = signatures.activeParameter ?? 100
            };

            return(Task.FromResult(signatureHelp));
        }
        public void SignatureDescriptions(Type conceptInfoType, string expectedDescription)
        {
            var description = ConceptInfoType.SignatureDescription(conceptInfoType);

            Assert.AreEqual(expectedDescription, description);
        }