Beispiel #1
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
        //#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            List <LocationOrLocationLink> items = new List <LocationOrLocationLink>();

            (var code, var lines, var tree) = bufferManager.Get(request.TextDocument.Uri.ToString());
            int c = request.Position.Character;
            int l = request.Position.Line;

            router.Window.LogInfo("definition requested");
            if (lines == null || tree == null)
            {
                return(items);
            }

            string token = lines[l][c].ToString();

            if (lines[l][c].ToString().IsIdentifier())
            {
                for (int i = c + 1; i < lines[l].Length && lines[l][i].ToString().IsIdentifier(); i++)
                {
                    token += lines[l][i];
                }
                for (int i = c - 1; i >= 0 && lines[l][i].ToString().IsIdentifier(); i--)
                {
                    token = lines[l][i] + token;
                }
            }
            else
            {
                return(items);
            }
            if (token.IsKeyword())
            {
                return(items);
            }


            //Context startOfSearch = FindContextAtLine(l, tree);
            //if (startOfSearch == null) return items;

            var def = FindDefinition(token, tree);

            if (def == null)
            {
                return(items);
            }

            var start = DocumentHighlightHandler.GetPosition(code, def.Characters.Start);
            var end   = DocumentHighlightHandler.GetPosition(code, def.Characters.End);

            router.Window.LogInfo("definition provided " + def);

            return(new LocationOrLocationLinks(new Location()
            {
                Range = new Range(start, end), Uri = request.TextDocument.Uri
            }));
        }
Beispiel #2
0
        public async Task <CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
        {
            router.Window.LogInfo("completion request");
            (var code, var lines, var tree) = bufferManager.Get(request.TextDocument.Uri.ToString());
            var table = bufferManager.GetTable(request.TextDocument.Uri.ToString());
            int c     = request.Position.Character;
            int l     = request.Position.Line;

            if (lines == null)
            {
                return(new CompletionList());
            }

            string token = lines[l][c].ToString();

            int i = GetChar(l, c, code);

            router.Window.LogInfo(i.ToString());

            var context = tree.GetFirstAtChar(i);

            router.Window.LogInfo(tree.ToString());
            router.Window.LogInfo(i.ToString());
            router.Window.LogInfo(context.ToString());

            //creating items
            List <CompletionItem> items = new List <CompletionItem>();

            if (context is FileContext)
            {
                items.Add(CreateKeyword("namespace "));
                items.Add(CreateKeyword("using "));
                items.Add(CreateKeyword("class "));
            }
            else if (context is ClassBodyContext)
            {
                items.Add(CreateKeyword("var "));
                items.Add(CreateKeyword("def "));
                items.Add(CreateKeywordDrop("public:\n\t", request.Position));
                items.Add(CreateKeywordDrop("private:\n\t", request.Position));
                items.Add(CreateKeywordDrop("internal:\n\t", request.Position));
            }
            else
            {
                GetMembers(table, items);
            }


            return(items);
        }
        public async Task <DocumentHighlightContainer> Handle(DocumentHighlightParams request, CancellationToken cancellationToken)
        {
            (var code, var lines, var tree) = bufferManager.Get(request.TextDocument.Uri.ToString());
            int c = request.Position.Character;
            int l = request.Position.Line;

            if (lines == null)
            {
                return(new DocumentHighlight[0]);
            }

            string token = lines[l][c].ToString();

            if (lines[l][c].ToString().IsIdentifier())
            {
                for (int i = c + 1; i < lines[l].Length && lines[l][i].ToString().IsIdentifier(); i++)
                {
                    token += lines[l][i];
                }
                for (int i = c - 1; i >= 0 && lines[l][i].ToString().IsIdentifier(); i--)
                {
                    token = lines[l][i] + token;
                }
            }
            else
            {
                return(new DocumentHighlight[0]);
            }
            if (token.IsKeyword())
            {
                return(new DocumentHighlight[0]);
            }

            List <DocumentHighlight> highlights = new List <DocumentHighlight>();

            for (int lineNumber = 1; lineNumber < lines.Length; lineNumber++)
            {
                var matches = Regex.Matches(lines[lineNumber], token);
                foreach (Match match in matches)
                {
                    highlights.Add(new DocumentHighlight()
                    {
                        Range = new Range(new Position(lineNumber, match.Index), new Position(lineNumber, match.Index + match.Length))
                    });
                }
            }
            return(highlights);
        }
        public async Task <TextEditContainer> Handle(DocumentOnTypeFormattingParams request, CancellationToken cancellationToken)
        {
            (string code, string[] lines, Context tree) = bufferManager.Get(request.TextDocument.Uri.ToString());
            List <TextEdit> edits = new List <TextEdit>();

            int    ln   = request.Position.Line - 1;
            string line = lines[ln];

            //if (new Regex("^.*{ *(\r\n|\r|\n)$").IsMatch(line))
            //{
            //    router.Window.LogInfo($"\"{line}\"");
            //    if (!new Regex("^ *{").IsMatch(line))
            //    {
            //        router.Window.LogInfo(request.Character + "," + request.Position.Line);
            //        edits.Add(new TextEdit() { NewText = "\n", Range = GetRangeAt(ln, line.LastIndexOf('{')) });
            //    }
            //}



            return(edits);
        }