MakeRelativeToFile() public static method

Returns a path to filePath if you start in a folder where the file relativeToPath is located.
public static MakeRelativeToFile ( string filePath, string relativeToPath ) : string
filePath string C:\A\B\1.txt
relativeToPath string C:\C\D\2.txt
return string
コード例 #1
0
        public HtmlElementInfo GenerateHyperlinkToReferences(ISymbol symbol, bool isLargeFile = false)
        {
            string symbolId = SymbolIdService.GetId(symbol);

            string referencesFilePath = Path.Combine(ProjectDestinationFolder, Constants.ReferencesFileName, symbolId + ".html");
            string href = Paths.MakeRelativeToFile(referencesFilePath, documentDestinationFilePath);

            href = href.Replace('\\', '/');

            var result = new HtmlElementInfo
            {
                Name       = "a",
                Attributes =
                {
                    ["id"]     = symbolId,
                    ["href"]   = href,
                    ["target"] = "n",
                },
                DeclaredSymbol   = symbol,
                DeclaredSymbolId = symbolId
            };

            if (!isLargeFile)
            {
                var dataGlyph = string.Format("{0},{1}",
                                              SymbolIdService.GetGlyphNumber(symbol),
                                              GetSymbolDepth(symbol));
                result.Attributes.Add("data-glyph", dataGlyph);
            }

            return(result);
        }
        private string AddOtherFileRelativeToProject(string filePath)
        {
            var relativePath = Paths.MakeRelativeToFile(filePath, ProjectFilePath);

            relativePath = relativePath.Replace("..", "parent");

            OtherFiles.Add(relativePath);

            return(relativePath);
        }
コード例 #3
0
        public HtmlElementInfo GenerateHyperlink(
            ISymbol symbol,
            string symbolId,
            SyntaxTree syntaxTree,
            out string assemblyName)
        {
            string href = null;

            assemblyName = SymbolIdService.GetAssemblyId(GetAssemblyFromSymbol(symbol));

            // if it's in a different assembly, use the URL to a redirecting file for that assembly
            if (assemblyName != Document.Project.AssemblyName)
            {
                href = GetAbsoluteLink(symbolId, assemblyName);
            }
            else // it's in the same assembly, we can just use the direct path without redirects
            {
                string referencedSymbolDestinationFilePath = null;
                if (symbol.Locations.Length > 1)
                {
                    referencedSymbolDestinationFilePath = Path.Combine(
                        SolutionDestinationFolder,
                        assemblyName,
                        Constants.PartialResolvingFileName,
                        symbolId);
                }
                else
                {
                    var referenceRelativeFilePath = Paths.GetRelativePathInProject(syntaxTree, Document.Project);
                    referencedSymbolDestinationFilePath = Path.Combine(projectGenerator.ProjectDestinationFolder, referenceRelativeFilePath);
                }

                href = Paths.MakeRelativeToFile(referencedSymbolDestinationFilePath, documentDestinationFilePath) + ".html";
                if (referencedSymbolDestinationFilePath + ".html" == documentDestinationFilePath)
                {
                    href = "";
                }
                else
                {
                    href = href.Replace('\\', '/');
                }

                href = href + "#" + symbolId;
            }

            return(new HtmlElementInfo
            {
                Name = "a",
                Attributes =
                {
                    { "href", href },
                }
            });
        }
コード例 #4
0
        private void GenerateTypeScriptFile(string filePath)
        {
            var projectSourceFolder = Path.GetDirectoryName(ProjectFilePath);

            if (!Path.IsPathRooted(filePath))
            {
                filePath = Path.Combine(Path.GetDirectoryName(ProjectFilePath), filePath);
            }

            SolutionGenerator.AddTypeScriptFile(filePath);

            var relativePath = Paths.MakeRelativeToFile(filePath, ProjectFilePath);

            relativePath = relativePath.Replace("..", "parent");
            OtherFiles.Add(relativePath);
        }
コード例 #5
0
        private HtmlElementInfo TryProcessPartialKeyword(INamedTypeSymbol symbol)
        {
            if (symbol.Locations.Length > 1)
            {
                string symbolId = SymbolIdService.GetId(symbol);

                string partialFilePath = Path.Combine(ProjectDestinationFolder, Constants.PartialResolvingFileName, symbolId + ".html");
                string href            = Paths.MakeRelativeToFile(partialFilePath, documentDestinationFilePath);
                href = href.Replace('\\', '/');

                var result = new HtmlElementInfo()
                {
                    Name       = "a",
                    Attributes =
                    {
                        { "href",   href },
                        { "target", "s"  },
                    }
                };
                return(result);
            }

            return(null);
        }
コード例 #6
0
        private HtmlElementInfo TryProcessGuid(Classification.Range range)
        {
            var text      = range.Text;
            var spanStart = range.ClassifiedSpan.TextSpan.Start;
            var spanEnd   = range.ClassifiedSpan.TextSpan.End;

            if (text.StartsWith("@"))
            {
                text = text.Substring(1);
                spanStart++;
            }

            if (text.StartsWith("\"") && text.EndsWith("\"") && text.Length >= 2)
            {
                spanStart++;
                spanEnd--;
                text = text.Substring(1, text.Length - 2);
            }

            // quick check to reject non-Guids even before trying to parse
            if (text.Length != 32 && text.Length != 36 && text.Length != 38)
            {
                return(null);
            }

            if (!Guid.TryParse(text, out Guid guid))
            {
                return(null);
            }

            var symbolId = guid.ToString();

            var referencesFilePath = Path.Combine(
                SolutionDestinationFolder,
                Constants.GuidAssembly,
                Constants.ReferencesFileName,
                symbolId + ".html");
            string href = Paths.MakeRelativeToFile(referencesFilePath, documentDestinationFilePath);

            href = href.Replace('\\', '/');

            var link = new HtmlElementInfo
            {
                Name       = "a",
                Attributes =
                {
                    { "href",   href },
                    { "target", "n"  },
                },
                DeclaredSymbolId = symbolId
            };

            projectGenerator.AddReference(
                this.documentDestinationFilePath,
                Text,
                Constants.GuidAssembly,
                null,
                symbolId,
                spanStart,
                spanEnd,
                ReferenceKind.GuidUsage);

            return(link);
        }
コード例 #7
0
        private HtmlElementInfo GenerateLinks(ClassifiedRange range, string destinationHtmlFilePath, Dictionary <string, int> localSymbolIdMap)
        {
            HtmlElementInfo result = null;

            var localRelativePath = destinationHtmlFilePath.Substring(
                Path.Combine(
                    Paths.SolutionDestinationFolder,
                    Constants.TypeScriptFiles).Length);

            if (!string.IsNullOrEmpty(range.definitionSymbolId))
            {
                var definitionSymbolId = SymbolIdService.GetId(range.definitionSymbolId);

                if (range.IsSymbolLocalOnly())
                {
                    var localId = GetLocalId(definitionSymbolId, localSymbolIdMap);
                    result = new HtmlElementInfo
                    {
                        Name       = "span",
                        Attributes =
                        {
                            { "id",    "r" + localId + " rd" },
                            { "class", "r" + localId + " r"  }
                        }
                    };
                    return(result);
                }

                result = new HtmlElementInfo
                {
                    Name       = "a",
                    Attributes =
                    {
                        { "id",     definitionSymbolId                                                                      },
                        { "href",   "/TypeScriptFiles/" + Constants.ReferencesFileName + "/" + definitionSymbolId + ".html" },
                        { "target", "n"                                                                                     }
                    }
                };

                var searchString = range.searchString;
                if (!string.IsNullOrEmpty(searchString) && searchString.Length > 2)
                {
                    lock (declarations)
                    {
                        searchString = searchString.StripQuotes();
                        if (IsWellFormed(searchString))
                        {
                            var declaration = string.Join(";",
                                                          searchString,                            // symbol name
                                                          definitionSymbolId,                      // 8-byte symbol ID
                                                          range.definitionKind,                    // kind (e.g. "class")
                                                          Markup.EscapeSemicolons(range.fullName), // symbol full name and signature
                                                          GetGlyph(range.definitionKind)           // glyph number
                                                          );
                            declarations.Add(declaration);
                        }
                    }
                }
            }

            if (range.hyperlinks == null || range.hyperlinks.Length == 0)
            {
                return(result);
            }

            var hyperlink = range.hyperlinks[0];
            var symbolId  = SymbolIdService.GetId(hyperlink.symbolId);

            if (range.IsSymbolLocalOnly() || localSymbolIdMap.ContainsKey(symbolId))
            {
                var localId = GetLocalId(symbolId, localSymbolIdMap);
                result = new HtmlElementInfo
                {
                    Name       = "span",
                    Attributes =
                    {
                        { "class", "r" + localId + " r" }
                    }
                };
                return(result);
            }

            var hyperlinkDestinationFile = Path.GetFullPath(hyperlink.sourceFile);

            hyperlinkDestinationFile = GetDestinationFilePath(hyperlinkDestinationFile);

            string href = "";

            if (!string.Equals(hyperlinkDestinationFile, destinationHtmlFilePath, StringComparison.OrdinalIgnoreCase))
            {
                href = Paths.MakeRelativeToFile(hyperlinkDestinationFile, destinationHtmlFilePath);
                href = href.Replace('\\', '/');
            }

            href = href + "#" + symbolId;

            if (result == null)
            {
                result = new HtmlElementInfo
                {
                    Name       = "a",
                    Attributes =
                    {
                        { "href",   href },
                        { "target", "s"  },
                    }
                };
            }
            else if (!result.Attributes.ContainsKey("href"))
            {
                result.Attributes.Add("href", href);
                result.Attributes.Add("target", "s");
            }

            lock (this.references)
            {
                var lineNumber      = range.lineNumber + 1;
                var linkToReference = ".." + localRelativePath + "#" + lineNumber.ToString();
                var start           = range.column;
                var end             = range.column + range.text.Length;
                var lineText        = Markup.HtmlEscape(range.lineText, ref start, ref end);
                var reference       = new Reference
                {
                    FromAssemblyId       = Constants.TypeScriptFiles,
                    ToAssemblyId         = Constants.TypeScriptFiles,
                    FromLocalPath        = localRelativePath.Substring(0, localRelativePath.Length - ".html".Length).Replace('\\', '/'),
                    Kind                 = ReferenceKind.Reference,
                    ToSymbolId           = symbolId,
                    ToSymbolName         = range.text,
                    ReferenceLineNumber  = lineNumber,
                    ReferenceLineText    = lineText,
                    ReferenceColumnStart = start,
                    ReferenceColumnEnd   = end,
                    Url = linkToReference.Replace('\\', '/')
                };

                if (!references.TryGetValue(symbolId, out List <Reference> bucket))
                {
                    bucket = new List <Reference>();
                    references.Add(symbolId, bucket);
                }

                bucket.Add(reference);
            }

            return(result);
        }