Skip to content

Update f1_keywords#20069

Merged
BillWagner merged 1 commit intodotnet:masterfrom
Youssef1313:patch-31
Aug 31, 2020
Merged

Update f1_keywords#20069
BillWagner merged 1 commit intodotnet:masterfrom
Youssef1313:patch-31

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Aug 14, 2020

This is the code I used to generate this:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace F1KeywordsTool
{
    public static class Program
    {
        private async static Task<string> GetUrlContentAsync(string url)
        {
            using var client = new HttpClient();
            using HttpResponseMessage response = await client.GetAsync(url);
            using HttpContent content = response.Content;
            return await content.ReadAsStringAsync();
        }

        private async static Task<string> GetEnumSourceCodeAsync()
        {
            return await GetUrlContentAsync("https://raw.githubusercontent.com/dotnet/roslyn/master/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs");
        }

        private async static Task<IEnumerable<string>> GetAlreadyDocumentedErrorNumbersAsync()
        {
            string content1 = await GetUrlContentAsync("https://github.com/dotnet/docs/tree/master/docs/csharp/misc");
            string content2 = await GetUrlContentAsync("https://github.com/dotnet/docs/tree/master/docs/csharp/language-reference/compiler-messages");
            return Regex.Matches(content1, @"title=""(cs\d{4})\.md""", RegexOptions.IgnoreCase).Select(m => m.Groups[1].Value).Concat(
                Regex.Matches(content2, @"title=""(cs\d{4})\.md""", RegexOptions.IgnoreCase).Select(m => m.Groups[1].Value)
                );
        }

        private async static Task<IEnumerable<string>> GetUndocumentedErrorNumbersAsync()
        {
            IEnumerable<string> all = await GetAllRoslynErrorNumbersAsync();
            IEnumerable<string> documented = await GetAlreadyDocumentedErrorNumbersAsync();
            return all.Except(documented, StringComparer.OrdinalIgnoreCase);
        }

        private async static Task<IEnumerable<string>> GetAllRoslynErrorNumbersAsync()
        {
            string sourceCode = await GetEnumSourceCodeAsync();
            SyntaxNode root = await CSharpSyntaxTree.ParseText(sourceCode).GetRootAsync();

            // This line didn't work for some reason.
            //return root.DescendantTokens(token => token.IsKind(SyntaxKind.NumericLiteralToken)).Select(t => $"CS{t.ValueText.PadLeft(4, '0')}");

            return root.DescendantTokens().Where(t => t.IsKind(SyntaxKind.NumericLiteralToken)).Select(t => $"CS{t.ValueText.PadLeft(4, '0')}");
        }

        public static async Task Main()
        {
            IEnumerable<string> undocumented = await GetUndocumentedErrorNumbersAsync();
            await File.WriteAllLinesAsync("Undocumented.txt", undocumented.Select(s => $@"  - ""{s}"""));
        }
    }
}

Important note

This relies on the currently defined error numbers in dotnet/roslyn repository, error numbers that were retired won't now exist. (I think that should be okay since Visual Studio wasn't relying (and still not relying) on f1, which may be fixed in dotnet/roslyn#46850)

Fixes #20034

- "CS0003"
- "CS0004"
- "CS0008"
- "CS0012"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one example where the error message is already documented but existed here. So, this f1 keyword was duplicated in this file and in the actual documentation.

Copy link
Member Author

@Youssef1313 Youssef1313 Aug 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillWagner, while I was testing what Visual Studio will do in the case of duplicated f1 keywords in multiple articles, I noticed that all error messages goes to a Bing search after clicking F1. So, the f1_keywords metadata seems to be not working at all.

I opened an issue for that. dotnet/roslyn#46829

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋 I dug into this problem before, see dotnet/roslyn#40863 and #16448. I think the main sticking point was finding out what the new link should be for the f1 service - as I presume the msdn URL for is now deprecated.

If you did want to take it further, the NuGet repo has a good example, as it's set up to work for their error codes. Should be a fairly easy thing to implement, once someone can find out what that links meant to be! 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋 I dug into this problem before, see dotnet/roslyn#40863 and #16448. I think the main sticking point was finding out what the new link should be for the f1 service - as I presume the msdn URL for is now deprecated.

If you did want to take it further, the NuGet repo has a good example, as it's set up to work for their error codes. Should be a fairly easy thing to implement, once someone can find out what that links meant to be! 😄

Copy link
Member Author

@Youssef1313 Youssef1313 Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisMaddock Thanks!! That's really really useful.
What I can't understand is, what's the problem to hook the error messages with the link https://msdn.microsoft.com/query/dev16.query?appId=Dev16IDEF1&l=EN-US&k=k(ERROR_ID);k(DevLang-csharp)&rd=true..

cc: @mairaw

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd presumed that link should be deprecated, given we've been replacing MSDN links everywhere else. There was a couple of other questions around filling in the appropriate appId and culture, but I assume that info is discoverable within Roslyn in some way. I think I was waiting on more info as to the official link we should be using here, and then other priorities came up, as they always do. 😄

I'm not a Microsoft employee though - just a guy with a lot of compiler errors! So perhaps best to hear from the experts instead. :-)

Copy link
Member Author

@Youssef1313 Youssef1313 Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisMaddock The f1 for keywords in the latest visual studio still uses that msdn link. If you, for example, press f1 on an await keyword in the latest visual studio, it will open a similar msdn link.

https://msdn.microsoft.com/query/dev16.query?appId=Dev16IDEF1&l=EN-US&k=k(await_CSharpKeyword);k(DevLang-csharp)&rd=true.

Based on the fact that C# keywords using that same link, I don't think see a problem using that same link too for error messages. I'll wait for someone to confirm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 😄 Hope it gets merged soon!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisMaddock I hope that too.
and many thanks for the information you provided, which is incredibly helpful.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After all this work, I think this is ready.

It will also help us have a list of those warnings we haven't documented.

Thanks @Youssef1313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential problems with f1 keywords for error messages

4 participants