Пример #1
0
        internal static string GetSignatureHelp(string scriptFile, int caret)
        {
            Output.WriteLine("GetSignatureHelp");

            var script = new SourceInfo(scriptFile);

            string result = null;

            if (script.Content.IsEmpty())
            {
                throw new Exception("The file containing code is empty");
            }

            if (!script.RawFile.EndsWith(".g.cs"))
            {
                CSScriptHelper.DecorateIfRequired(ref script.Content, ref caret);
            }

            Project project = CSScriptHelper.GenerateProjectFor(script);
            var     sources = project.Files
                              .Where(f => f != project.Script)
                              .Select(f => new Tuple <string, string>(File.ReadAllText(f), f))
                              .ToArray();

            string bestMatchIndex;
            var    items = Autocompleter.GetMethodSignatures(script.Content, caret, out bestMatchIndex, project.Refs, sources);

            result = $"{bestMatchIndex}\r\n" + items.Select(x => x.EscapeLB())
                     .JoinSerializedLines();

            return(result);
        }
Пример #2
0
        internal static DomRegion ResolveRaw(string scriptFile, int offset)
        {
            var script = new SourceInfo(scriptFile);

            if (script.Content.IsEmpty())
            {
                throw new Exception("The file containing code is empty");
            }

            DomRegion region = DomRegion.Empty;

            ParseAsCssDirective(script.Content, offset,
                                directive =>
            {
                region = CssSyntax.Resolve(directive);
            },
                                (directive, arg, extensions) =>
            {
                if (LookopDirectivePath(script, offset, directive, arg) is string file)
                {
                    region = new DomRegion
                    {
                        BeginColumn = -1,
                        BeginLine   = -1,
                        EndLine     = -1,
                        FileName    = file,
                        IsEmpty     = false
                    }
                }
                ;
                else
                {
                    region = CssSyntax.Resolve(directive);
                }
            });

            if (region.IsEmpty)
            {
                bool decorated = false;
                if (!script.RawFile.EndsWith(".g.cs"))
                {
                    decorated = CSScriptHelper.DecorateIfRequired(ref script.Content, ref offset);
                }

                Project project = CSScriptHelper.GenerateProjectFor(script);
                var     sources = project.Files
                                  .Where(f => f != project.Script)
                                  .Select(f => new Tuple <string, string>(File.ReadAllText(f), f))
                                  .ToArray();

                region = Autocompleter.ResolveSymbol(script.Content, offset, script.File, project.Refs, sources);
                if (decorated && region.FileName == script.File)
                {
                    CSScriptHelper.Undecorate(script.Content, ref region);
                }
            }

            return(region);
        }
Пример #3
0
        internal static string FindRefreneces(string scriptFile, int offset, string context)
        {
            Output.WriteLine("FindRefreneces");

            var script = new SourceInfo(scriptFile);

            if (script.Content.IsEmpty())
            {
                throw new Exception("The file containing code is empty");
            }

            bool decorated = false;

            if (!script.RawFile.EndsWith(".g.cs"))
            {
                decorated = CSScriptHelper.DecorateIfRequired(ref script.Content, ref offset);
            }

            Project project = CSScriptHelper.GenerateProjectFor(script);
            var     sources = project.Files
                              .Where(f => f != project.Script)
                              .Select(f => new Tuple <string, string>(File.ReadAllText(f), f))
                              .ToArray();

            var regions = new List <string>();

            if (context == "all")  // include definition and constructors
            {
                DomRegion[] refs = Autocompleter.GetSymbolSourceRefs(script.Content, offset, script.File, project.Refs, sources);
                foreach (DomRegion item in refs)
                {
                    DomRegion region = item;
                    if (decorated && item.FileName == script.File)
                    {
                        CSScriptHelper.Undecorate(script.Content, ref region);
                    }

                    regions.Add($"{item.FileName}({region.BeginLine},{item.BeginColumn}): ...");
                }
            }

            regions.AddRange(Autocompleter.FindReferences(script.Content, offset, script.File, project.Refs, sources));

            fullyLoaded = true;

            return(regions.Distinct().JoinBy("\n"));
        }
Пример #4
0
        internal static string GetMemberInfo(string scriptFile, int caret, bool collapseOverloads)
        {
            // Complete API for N++

            Output.WriteLine("GetMemberInfo");
            //Console.WriteLine("hint: " + hint);

            var    script = new SourceInfo(scriptFile);
            string result = null;

            if (script.Content.IsEmpty())
            {
                throw new Exception("The file containing code is empty");
            }

            void loockupDirective(string directive)
            {
                var css_directive = CssCompletionData.AllDirectives
                                    .FirstOrDefault(x => x.DisplayText == directive);

                if (css_directive != null)
                {
                    result = $"Directive: {css_directive.DisplayText}\n{css_directive.Description}";
                    result = result.NormalizeLineEnding().Replace("\r\n\r\n", "\r\n").TrimEnd();
                }
            };

            ParseAsCssDirective(script.Content, caret,
                                loockupDirective,
                                (directive, arg, extensions) =>
            {
                if (LookopDirectivePath(script, caret, directive, arg) is string file)
                {
                    result = $"File: {file}";
                }
                else
                {
                    loockupDirective(directive);
                }
            });

            if (result.HasText())
            {
                return(MemberInfoData.Serialize(new MemberInfoData {
                    Info = result
                }));
            }

            if (!script.RawFile.EndsWith(".g.cs"))
            {
                CSScriptHelper.DecorateIfRequired(ref script.Content, ref caret);
            }

            Project project = CSScriptHelper.GenerateProjectFor(script);
            var     sources = project.Files
                              .Where(f => f != script.File)
                              .Select(f => new Tuple <string, string>(File.ReadAllText(f), f))
                              .ToArray();

            int methodStartPosTemp;
            var items = Autocompleter.GetMemberInfo(script.Content, caret, out methodStartPosTemp, project.Refs, sources, includeOverloads: !collapseOverloads);

            if (collapseOverloads)
            {
                items = items.Take(1);
            }

            result = items.Select(x => new MemberInfoData {
                Info = x, MemberStartPosition = methodStartPosTemp
            })
                     .Select(MemberInfoData.Serialize)
                     .JoinSerializedLines();

            return(result);
        }
Пример #5
0
        internal static string GetTooltip(string scriptFile, int caret, string hint, bool shortHintedTooltips)
        {
            // Simplified API for ST3
            Output.WriteLine("GetTooltip");
            //Console.WriteLine("hint: " + hint);

            string result = null;

            var script = new SourceInfo(scriptFile);

            if (script.Content.IsEmpty())
            {
                throw new Exception("The file containing code is empty");
            }

            void loockupDirective(string directive)
            {
                var css_directive = CssCompletionData.AllDirectives
                                    .FirstOrDefault(x => x.DisplayText == directive);

                if (css_directive != null)
                {
                    result = $"Directive: {css_directive.DisplayText}\n{css_directive.Description}";
                    result = result.NormalizeLineEnding().Replace("\r\n\r\n", "\r\n").TrimEnd();
                }
            };

            ParseAsCssDirective(script.Content, caret,
                                loockupDirective,
                                (directive, arg, extensions) =>
            {
                if (LookopDirectivePath(script, caret, directive, arg) is string file)
                {
                    result = $"File: {file}";
                }
                else
                {
                    loockupDirective(directive);
                }
            });

            if (result.HasText())
            {
                return(result);
            }

            if (!script.RawFile.EndsWith(".g.cs"))
            {
                CSScriptHelper.DecorateIfRequired(ref script.Content, ref caret);
            }

            Project project = CSScriptHelper.GenerateProjectFor(script);
            var     sources = project.Files
                              .Where(f => f != project.Script)
                              .Select(f => new Tuple <string, string>(File.ReadAllText(f), f))
                              .ToArray();

            int methodStartPosTemp;
            var items = Autocompleter.GetMemberInfo(script.Content, caret, out methodStartPosTemp, project.Refs, sources, includeOverloads: hint.HasAny());

            fullyLoaded = true;
            if (hint.HasAny())
            {
                if (shortHintedTooltips)
                {
                    items = items.Select(x => x.Split('\n').FirstOrDefault()).ToArray();
                }

                int count = hint.Split(',').Count();
                result = items.FirstOrDefault(x =>
                {
                    return(SyntaxMapper.GetArgumentCount(x) == count);
                })
                         ?? items.FirstOrDefault();

                bool hideOverloadsSummary = false;
                if (result != null && hideOverloadsSummary)
                {
                    var lines = result.Split('\n').Select(x => x.TrimEnd('\r')).ToArray();
                    //(+ 1 overloads)
                    if (lines[0].EndsWith(" overloads)"))
                    {
                        try
                        {
                            lines[0] = lines[0].Split(new[] { "(+" }, StringSplitOptions.None).First().Trim();
                        }
                        catch { }
                    }
                    result = lines.JoinBy("\n");
                }
            }
            else
            {
                result = items.FirstOrDefault();
            }

            if (result.HasText())
            {
                result = result.NormalizeLineEnding().Replace("\r\n\r\n", "\r\n").TrimEnd();
            }

            return(result);
        }
Пример #6
0
        internal static IEnumerable <ICompletionData> GetCompletionRaw(string scriptFile, int caret, bool includDocumentation = false)
        {
            var script = new SourceInfo(scriptFile);

            if (script.Content.IsEmpty())
            {
                throw new Exception("The file containing code is empty");
            }

            IEnumerable <ICompletionData> completions = null;

            bool wasHandled = ParseAsCssDirective(script.Content, caret,
                                                  (directive) =>
            {
                completions = CssCompletionData.AllDirectives;
            },
                                                  (directive, arg, extensions) =>
            {
                if (directive.OneOf("//css_ac", "//css_autoclass"))
                {
                    completions = new[]
                    {
                        new CssCompletionData
                        {
                            CompletionText = "freestyle",
                            DisplayText    = "freestyle",
                            Description    = "Free style code without any entry point.",
                            CompletionType = CompletionType.directive
                        }
                    };
                }
                else
                {
                    completions = LookupDirectivePaths(script, caret, directive, arg, extensions)
                                  .Select(file => new CssCompletionData
                    {
                        CompletionText = Path.GetFileName(file),
                        DisplayText    = Path.GetFileName(file),
                        Description    = "File: " + file,
                        CompletionType = CompletionType.file
                    });
                }
            },
                                                  ignoreEmptyArgs: false);

            if (!wasHandled)
            {
                if (!script.RawFile.EndsWith(".g.cs"))
                {
                    CSScriptHelper.DecorateIfRequired(ref script.Content, ref caret);
                }

                Project project = CSScriptHelper.GenerateProjectFor(script);
                var     sources = project.Files
                                  .Where(f => f != project.Script)
                                  .Select(f => new Tuple <string, string>(File.ReadAllText(f), f))
                                  .ToArray();

                completions = Autocompleter.GetAutocompletionFor(script.Content, caret, project.Refs, sources, includDocumentation);

                var count = completions.Count();
            }
            return(completions);
        }