protobuflab / protobuf-langserver

MIT License
0 stars 1 forks source link

Create a document snapshot data type. #4

Closed NTaylorMullen closed 5 years ago

NTaylorMullen commented 5 years ago

Document snapshots represent the state of a document at a certain point in time. For instance if a user is typing character by character abc this would result in 1-3 document snapshots depending on how frequently the IDE client on the other end of the language server sent updates. For instance the client could do: a at 0 -> b at 1 -> c at 2 resulting in 3 document snapshots:

  1. a
  2. ab
  3. abc

But it could also be sent as ab at 0 -> c at 2 resulting in 2 document snaphots

  1. ab
  2. abc

This issue doesn't track creating/updating snapshots its reason is to provide a common type that other infrastructure bits can use to make decisions.

Basic structure of a document snapshot

string Path { get; }

long Version { get; }

// We should probably just use Roslyn's data type here for text because it's a hackathon
Task<SourceText> GetTextAsync();

// Dependent on https://github.com/protobuflab/protobuf-langserver/issues/1
Task<SyntaxTreeType> GetSyntaxTreeAsync();

Document snapshots are immutable and data that's calculated to provide results to methods such as GetSyntaxTreeAsync and GetTextAsync are typically memoized.

ryanbrandenburg commented 5 years ago

https://github.com/protobuflab/protobuf-langserver/commit/b03f9bdcd8c53e24a243416b4e807bcbfced42e3