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: ConceptTypeTools.GetParameters(valid.conceptType).Count, documentation: signaturesWithDocumentation.Single(sig => sig.ConceptType == valid.conceptType) )) .OrderBy(valid => valid.activeParamater >= valid.parameterCount) .ThenBy(valid => valid.parameterCount) .ThenBy(valid => valid.conceptType.TypeName) .ToList(); var activeParameter = sortedConcepts.First().activeParamater; return(sortedConcepts.Select(sorted => sorted.documentation).ToList(), 0, activeParameter); }
private int GetActiveParameterForValidConcept(ConceptType conceptType) { var activeParameter = 0; // we have parsed some members successfully for this concept type if (LastTokenParsed.ContainsKey(conceptType)) { activeParameter = ConceptTypeTools.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(conceptType.Keyword, LastTokenParsed[conceptType].Value, StringComparison.InvariantCultureIgnoreCase); if (atKeyword || !atLastParsed) { activeParameter++; } } return(activeParameter); }