[tintd] Add more comments

Bug: tint:2127
Change-Id: Ic8cec3bc4ffd346bcd6c36241c6e664b9847b042
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/180486
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/tint/lang/wgsl/ls/hover.cc b/src/tint/lang/wgsl/ls/hover.cc
index 5ffbe47..fe9f123 100644
--- a/src/tint/lang/wgsl/ls/hover.cc
+++ b/src/tint/lang/wgsl/ls/hover.cc
@@ -64,6 +64,7 @@
 
 namespace {
 
+/// @returns a lsp::MarkedStringWithLanguage with the content @p wgsl, using the language `wgsl`
 lsp::MarkedStringWithLanguage WGSL(std::string wgsl) {
     lsp::MarkedStringWithLanguage str;
     str.language = "wgsl";
@@ -71,6 +72,7 @@
     return str;
 }
 
+/// PrintConstant() writes the constant value @p val as a WGSL value to the StringStream @p ss
 void PrintConstant(const core::constant::Value* val, StringStream& ss) {
     Switch(
         val,  //
@@ -98,6 +100,7 @@
         });
 }
 
+/// Variable() writes the hover information for the variable @p v to @p out
 void Variable(const sem::Variable* v, std::vector<lsp::MarkedString>& out) {
     StringStream ss;
     auto* kind = Switch(
@@ -122,6 +125,7 @@
     out.push_back(WGSL(ss.str()));
 }
 
+/// Function() writes the hover information for the function @p f to @p out
 void Function(const sem::Function* f, std::vector<lsp::MarkedString>& out) {
     StringStream ss;
     ss << "fn " << f->Declaration()->name->symbol.NameView();
@@ -142,6 +146,8 @@
     out.push_back(WGSL(ss.str()));
 }
 
+/// Call() writes the hover information for a call to the function with the name @p name with
+/// semantic info @p c, to @p out
 void Call(std::string_view name, const sem::Call* c, std::vector<lsp::MarkedString>& out) {
     StringStream ss;
     ss << name << "(";
@@ -165,6 +171,7 @@
     out.push_back(WGSL(ss.str()));
 }
 
+/// Constant() writes the hover information for the constant value @p val to @p out
 void Constant(const core::constant::Value* val, std::vector<lsp::MarkedString>& out) {
     StringStream ss;
     PrintConstant(val, ss);
diff --git a/src/tint/lang/wgsl/ls/sem_tokens.cc b/src/tint/lang/wgsl/ls/sem_tokens.cc
index 3accd26..ddbd5a5 100644
--- a/src/tint/lang/wgsl/ls/sem_tokens.cc
+++ b/src/tint/lang/wgsl/ls/sem_tokens.cc
@@ -50,12 +50,17 @@
 
 namespace {
 
+/// Token describes a single semantic token, as returned by TextDocumentSemanticTokensFullRequest.
 struct Token {
+    /// The start position of the token
     lsp::Position position;
+    /// The kind of token. Maps to enumerators in SemToken.
     size_t kind = 0;
+    /// The length of the token in UTF-8 codepoints.
     size_t length = 0;
 };
 
+/// @returns a Token built from the source range @p range with the kind @p kind
 Token TokenFromRange(const tint::Source::Range& range, SemToken::Kind kind) {
     Token tok;
     tok.position = Conv(range.begin);
@@ -64,6 +69,8 @@
     return tok;
 }
 
+/// @returns the token kind for the expression @p expr, or nullptr if the expression does not have a
+/// token kind.
 std::optional<SemToken::Kind> TokenKindFor(const sem::Expression* expr) {
     return Switch<std::optional<SemToken::Kind>>(
         Unwrap(expr),  //
@@ -75,6 +82,7 @@
         [](tint::Default) { return std::nullopt; });
 }
 
+/// @returns all the semantic tokens in the file @p file, in sequential order.
 std::vector<Token> Tokens(File& file) {
     std::vector<Token> tokens;
     auto& sem = file.program.Sem();
@@ -102,6 +110,9 @@
                 tokens.push_back(TokenFromRange(a->member->source.range, SemToken::kMember));
             });
     }
+    std::sort(tokens.begin(), tokens.end(),
+              [](const Token& a, const Token& b) { return a.position < b.position; });
+
     return tokens;
 }
 
@@ -117,9 +128,6 @@
         Token last;
 
         auto tokens = Tokens(**file);
-        std::sort(tokens.begin(), tokens.end(),
-                  [](const Token& a, const Token& b) { return a.position < b.position; });
-
         for (auto tok : tokens) {
             if (last.position.line != tok.position.line) {
                 last.position.character = 0;
diff --git a/src/tint/lang/wgsl/ls/signature_help.cc b/src/tint/lang/wgsl/ls/signature_help.cc
index 9e0de3e..7644c74 100644
--- a/src/tint/lang/wgsl/ls/signature_help.cc
+++ b/src/tint/lang/wgsl/ls/signature_help.cc
@@ -41,8 +41,10 @@
 
 namespace {
 
-std::vector<lsp::ParameterInformation> Params(const core::intrinsic::TableData& data,
-                                              const core::intrinsic::OverloadInfo& overload) {
+/// @returns the parameter information for all the parameters of the intrinsic overload @p overload.
+std::vector<lsp::ParameterInformation> Params(const core::intrinsic::OverloadInfo& overload) {
+    auto& data = wgsl::intrinsic::Dialect::kData;
+
     std::vector<lsp::ParameterInformation> params;
     for (size_t i = 0; i < overload.num_parameters; i++) {
         lsp::ParameterInformation param_out;
@@ -93,6 +95,8 @@
     return index;
 }
 
+/// PrintOverload() emits a description of the intrinsic overload @p overload of the function with
+/// name @p intrinsic_name to @p ss.
 void PrintOverload(StyledText& ss,
                    core::intrinsic::Context& context,
                    const core::intrinsic::OverloadInfo& overload,
@@ -192,7 +196,7 @@
                for (size_t i = 0; i < intrinsic_info.num_overloads; i++) {
                    auto& overload = data[intrinsic_info.overloads + i];
 
-                   auto params = Params(data, overload);
+                   auto params = Params(overload);
 
                    auto type_mgr = core::type::Manager::Wrap(program.Types());
                    auto symbols = SymbolTable::Wrap(program.Symbols());