From 9f62922512255eebf6ccaf2ae559cee1bdf96733 Mon Sep 17 00:00:00 2001 From: Jiayin Pei Date: Fri, 23 Sep 2022 09:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=F0=9F=9A=80=F0=9F=9A=80=20(#8185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: return LinkType.External if host name is not removed (#8182) * Update default document url in language server (#8183) Co-authored-by: Ying Hua --- docs/specs/lsp.yml | 2 +- src/docfx/build/link/LinkResolver.cs | 2 +- src/docfx/serve/LanguageServerBuilder.cs | 2 +- test/docfx.Test/lib/UrlUtilityTest.cs | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/specs/lsp.yml b/docs/specs/lsp.yml index 5be1be7a1df..411366fc115 100644 --- a/docs/specs/lsp.yml +++ b/docs/specs/lsp.yml @@ -36,7 +36,7 @@ languageServer: a.md: "[Test](non-existed.md)" - expectDiagnostics: a.md: [] - docfx.yml: [{ "code": "yaml-syntax-error" }] + docfx.yml: [{ "code": "yaml-syntax-error", "codeDescription": { "href": "https://review.learn.microsoft.com/en-us/help/contribute/validation-ref/doc-not-available?branch=main" } }] - editFiles: docfx.yml: - expectDiagnostics: diff --git a/src/docfx/build/link/LinkResolver.cs b/src/docfx/build/link/LinkResolver.cs index e3c068331e4..91b9e852a89 100644 --- a/src/docfx/build/link/LinkResolver.cs +++ b/src/docfx/build/link/LinkResolver.cs @@ -162,7 +162,7 @@ public LinkResolver( resolvedHref = UrlUtility.RemoveLeadingHostName(resolvedHref, _config.AlternativeHostName); } - return (errors, resolvedHref, fragment, LinkType.AbsolutePath, null, false); + return (errors, resolvedHref, fragment, resolvedHref != href ? LinkType.AbsolutePath : LinkType.External, null, false); } // Cannot resolve the file, leave href as is diff --git a/src/docfx/serve/LanguageServerBuilder.cs b/src/docfx/serve/LanguageServerBuilder.cs index 200b2f0356a..fd78f184495 100644 --- a/src/docfx/serve/LanguageServerBuilder.cs +++ b/src/docfx/serve/LanguageServerBuilder.cs @@ -148,7 +148,7 @@ private void PublishDiagnosticsParams(ErrorList errors, IEnumerable private static Diagnostic ConvertToDiagnostics(Error error, SourceInfo source) { - var documentUrl = error.DocumentUrl ?? "https://review.docs.microsoft.com/en-us/help/contribute/validation-ref/doc-not-available?branch=main"; + var documentUrl = error.DocumentUrl ?? "https://review.learn.microsoft.com/en-us/help/contribute/validation-ref/doc-not-available?branch=main"; return new Diagnostic { Range = new( diff --git a/test/docfx.Test/lib/UrlUtilityTest.cs b/test/docfx.Test/lib/UrlUtilityTest.cs index f50fe11b310..85e8cc03157 100644 --- a/test/docfx.Test/lib/UrlUtilityTest.cs +++ b/test/docfx.Test/lib/UrlUtilityTest.cs @@ -212,6 +212,10 @@ public static void StandardizeBookmarks(string uid, string expectedBookmark) [InlineData("https://docs.com/c", "docs.com", false, "/c")] [InlineData("https://docs.com/en-us/c", "docs1.com", true, "https://docs.com/en-us/c")] [InlineData("https://docs.com/", "docs.com", true, "/")] + [InlineData("https://docs.com/#bookmark", "docs.com", true, "/#bookmark")] + [InlineData("https://docs.com/?query=value", "docs1.com", true, "https://docs.com/?query=value")] + [InlineData("https://docs.com/c#bookmark", "docs1.com", true, "https://docs.com/c#bookmark")] + [InlineData("https://docs.com/c?query=value", "docs.com", true, "/c?query=value")] public static void RemoveHostName(string url, string hostName, bool removeLocale, string expected) { var result = UrlUtility.RemoveLeadingHostName(url, hostName, removeLocale);