Repository: carbon-language/carbon-lang
File: toolchain/language_server/context.h (C/C++)

Code before:

    // Changes the file's text, updating dependent state.
    auto SetText(Context& context, std::optional<int64_t> version,
                 llvm::StringRef text) -> void;

    auto ApplyChanges(
        Context& context, std::optional<int64_t> version,
        const std::vector<clang::clangd::TextDocumentContentChangeEvent>&
            content_changes) -> void;

    auto tree_and_subtrees() const -> const Parse::TreeAndSubtrees& {
      return *tree_and_subtrees_;
    }

   private:
    // The filename, stable across instances.
    clang::clangd::URIForFile uri_;

    // Current file content, and derived values.
    std::unique_ptr<SourceBuffer> source_;
    std::unique_ptr<SharedValueStores> value_stores_;
    std::unique_ptr<Lex::TokenizedBuffer> tokens_;
    std::unique_ptr<Parse::Tree> tree_;
    std::unique_ptr<Parse::TreeAndSubtrees> tree_and_subtrees_;

    // converts (line, row) position in source code to index
    auto PositionToIndex(const clang::clangd::Position& position) -> size_t;
    auto PositionToIndex(const std::string& contents,
                         const clang::clangd::Position& position) -> size_t;
  };

  // `vlog_stream` is optional; other parameters are required.
  explicit Context(llvm::raw_ostream* vlog_stream, DiagnosticConsumer* consumer,
                   clang::clangd::LSPBinder::RawOutgoing* outgoing)
      : vlog_stream_(vlog_stream),
        file_emitter_(consumer),
        no_loc_emitter_(consumer),
        outgoing_(outgoing) {}

  // Returns a reference to the file if it's known, or diagnoses and returns
  // null.
  auto LookupFile(llvm::StringRef filename) -> File*;

  auto vlog_stream() -> llvm::raw_ostream* { return vlog_stream_; }
  auto file_emitter() -> FileDiagnosticEmitter& { return file_emitter_; }
  auto no_loc_emitter() -> NoLocDiagnosticEmitter& { return no_loc_emitter_; }
  auto outgoing() -> clang::clangd::LSPBinder::RawOutgoing& {
    return *outgoing_;
  }

  auto files() -> Map<std::string, File>& { return files_; }

Review comment (suggestion):
```suggestion
    // Converts (line, row) position in source code to index.
```

As noted above, we use sentence punctuation in comments.

Code after:

    // Changes the file's text, updating dependent state.
    auto SetText(Context& context, std::optional<int64_t> version,
                 llvm::StringRef text) -> void;

    auto text() const -> llvm::StringRef { return source_->text(); }

    auto tree_and_subtrees() const -> const Parse::TreeAndSubtrees& {
      return *tree_and_subtrees_;
    }

   private:
    // The filename, stable across instances.
    clang::clangd::URIForFile uri_;

    // Current file content, and derived values.
    std::unique_ptr<SourceBuffer> source_;
    std::unique_ptr<SharedValueStores> value_stores_;
    std::unique_ptr<Lex::TokenizedBuffer> tokens_;
    std::unique_ptr<Parse::Tree> tree_;
    std::unique_ptr<Parse::TreeAndSubtrees> tree_and_subtrees_;
  };

  // `vlog_stream` is optional; other parameters are required.
  explicit Context(llvm::raw_ostream* vlog_stream, DiagnosticConsumer* consumer,
                   clang::clangd::LSPBinder::RawOutgoing* outgoing)
      : vlog_stream_(vlog_stream),
        file_emitter_(consumer),
        no_loc_emitter_(consumer),
        outgoing_(outgoing) {}

  // Returns a reference to the file if it's known, or diagnoses and returns
  // null.
  auto LookupFile(llvm::StringRef filename) -> File*;

  auto vlog_stream() -> llvm::raw_ostream* { return vlog_stream_; }
  auto file_emitter() -> FileDiagnosticEmitter& { return file_emitter_; }
  auto no_loc_emitter() -> NoLocDiagnosticEmitter& { return no_loc_emitter_; }
  auto outgoing() -> clang::clangd::LSPBinder::RawOutgoing& {
    return *outgoing_;
  }

  auto files() -> Map<std::string, File>& { return files_; }

 private:
  // Diagnostic and output streams.
  llvm::raw_ostream* vlog_stream_;
  FileDiagnosticEmitter file_emitter_;
  NoLocDiagnosticEmitter no_loc_emitter_;
  clang::clangd::LSPBinder::RawOutgoing* outgoing_;