示例#1
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);
        }
示例#2
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"));
        }