Ejemplo n.º 1
0
        bool SuggestionsBasedOnSyntax(GetCodeSuggestionsRequest codeCompletion, out IList <SuggestItem> suggestItems)
        {
            suggestItems = new List <SuggestItem>();

            if (!ValidateData(codeCompletion))
            {
                return(false);
            }

            var textPosition = new TextPosition(
                new LineNumber(codeCompletion.CaretPosition.Line),
                new CharacterNumber(codeCompletion.CaretPosition.Character));

            var syntax         = SyntaxLanguage.FromString(codeCompletion.SyntaxType).Syntax;
            var normalizedText = codeCompletion.Text.NormalizeLineEndings();
            var success        = _suggestionFactory.SuggestionsBasedOnSyntax(
                syntax,
                new SuggestionDependentData(
                    _engine.MainPackage,
                    _engine.Compiler,
                    AbsoluteFilePath.Parse(codeCompletion.Path),
                    normalizedText,
                    textPosition.ToOffset(normalizedText)),
                out suggestItems);

            if (success)
            {
                return(true);
            }

            _errors.OnNext(new Error(ErrorCode.InvalidData, string.Format("Tried to create suggestions for unknown syntax type {0}", new[] { codeCompletion.SyntaxType })));

            return(false);
        }
Ejemplo n.º 2
0
        Optional <Source> TryGoToDefinitionBasedOnType(GotoDefinitionRequest goToDefinition)
        {
            if (!ValidateData(goToDefinition))
            {
                return(Optional.None());
            }

            if (_engine.Compiler == null)
            {
                return(Optional.None());
            }

            var textPosition = new TextPosition(
                new LineNumber(goToDefinition.CaretPosition.Line),
                new CharacterNumber(goToDefinition.CaretPosition.Character));

            Source source;
            var    syntax         = SyntaxLanguage.FromString(goToDefinition.SyntaxType).Syntax;
            var    normalizedText = goToDefinition.Text.NormalizeLineEndings();
            var    success        = _gotoDefinitionFactory.TryGotoDefinitionBasedOnSyntax(
                syntax,
                new GotoDefinitionData(
                    _engine.MainPackage,
                    _engine.Compiler,
                    AbsoluteFilePath.Parse(goToDefinition.Path),
                    normalizedText,
                    textPosition.ToOffset(normalizedText)),
                out source);

            if (success)
            {
                return(source);
            }

            _errors.OnNext(new Error(ErrorCode.InvalidData, string.Format("Tried to go to definition in unknown syntax code {0}", goToDefinition.SyntaxType)));

            return(Optional.None());
        }