Skip to content

Library sync and cache invalidation #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 25, 2025
Merged

Library sync and cache invalidation #903

merged 15 commits into from
Apr 25, 2025

Conversation

castwide
Copy link
Owner

@castwide castwide commented Apr 19, 2025

  • Library methods that use cursors need to sync_catalog first.
  • Ensure that changing a method's return type in YARD tags resets the inference cache.
  • Ensure that changes to local pins in source maps reset the inference cache.
  • Host attaches opened and unmerged sources to libraries

@castwide castwide requested a review from Copilot April 20, 2025 18:37
Copilot

This comment was marked as outdated.

@castwide castwide force-pushed the sync-and-cache branch 2 times, most recently from 17194aa to 5341745 Compare April 21, 2025 17:10
@castwide castwide requested a review from Copilot April 24, 2025 20:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses improvements to library syncing and cache invalidation by updating the way source maps are merged and refreshed, as well as refining how local pins and catalog synchronization are handled. Key changes include the removal of several tests for source map merge behavior in the specs, refactoring of the source map and library code to use a sync counter instead of thread management, and adjustments to the parsing and finalization logic in source processing.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
spec/source_map_spec.rb Removed multiple tests for merging behavior
spec/pin/method_spec.rb Minor stylistic changes with adjustments in test descriptions
spec/language_server/host/message_worker_spec.rb Update of message double construction and synchronization
lib/solargraph/source_map/data.rb New data wrapper for lazy generation of pins and locals
lib/solargraph/source_map.rb Refactored source map initialization and merging logic
lib/solargraph/source.rb Revised finalization and synchronization of source parsing
lib/solargraph/pin/method.rb Updated merging logic in nearly? method
lib/solargraph/library.rb Replaced thread management with a sync counter
lib/solargraph/language_server/host/message_worker.rb Introduced message prioritization logic in worker class
Comments suppressed due to low confidence (1)

spec/source_map_spec.rb:74

  • Removal of several tests for merging behaviors reduces coverage on source map merging functionality; consider adding replacement tests to validate that the intended merge behavior is still correctly handled.
  -  it "merges comment changes" do

@castwide
Copy link
Owner Author

The three major bottlenecks in library updates are source parsing, source mapping, and api_map cataloging. The top-level approach for improving them is to apply changes at the moment they're needed instead of when they're received.

  • Updating (synchronizing) sources creates a new source that tracks the changes without applying them. The library will parse them when a query requires the updates to be executed. This allows sources to queue changes from the language server (e.g., via textDocument/didChange) instead of triggering a parse for each change.
  • Source maps will not generate pins until they're required by a library catalog.
  • Source maps used to perform a #try_merge! to determine if a source map's pins could be merged into an existing map to reduce cataloging. Any benefit from this process was lost to the fact that the source map needed to be generated before it could be merged. JIT mapping in the library is ultimately more efficient.
  • We can explore whether try_merge! would be more effective as part of the Library#sync_catalog process, where it still might reduce ApiMap#catalog overhead. The question is how much the reduction in cataloging compares to the addition of merge attempts.

@castwide castwide merged commit 97fc1c2 into master Apr 25, 2025
8 checks passed
apiology added a commit to apiology/solargraph that referenced this pull request Apr 28, 2025
* Library sync and cache invalidation

* Stop sleeping in catalog threads in mingw

* JIT library sync without threads

* MessageWorker prioritizes messages

* Unused instance variable

* JIT source parsing

* Fix JIT source parsing

* Avoid unnecessary parsing in library

* JIT source mapping

* Specs

* Stale code

* Library#map! finds external requires

* Preserve SourceMap#try_merge!

* Force catalog after caching gemspecs

* Synchronize count check in Library#sync_catalog
castwide added a commit that referenced this pull request Jun 24, 2025
* Infer literal types and use them for signature selection

* Introduce tuple type via an RBS-based fill

* Use methods from the new tuple type for Array()

* Hold back on representing literal strings

* Resolve merge

* Update spec/source_map/clip_spec.rb

* Resolve merge issues

* Update test expectations

* [regression] Restore 'Unresolved call' typecheck for stdlib objects (#849)

The 'Unresolved call to' typecheck suppresses warnings for calls
against non-RBS-origin pins.  However, the labeling assigning :rbs as
the source of pins from conversions.rb was recently removed as part of
an unrelated cleanup.

* Lazy dynamic rebinding (#851)

* Lazy dynamic rebinding

* Stub failing test

* Move rebinding to Clip

* Restore fill for Class#allocate (#848)

* [regression] Ensure YardMap gems have return type for Class<T>.new (#850)

* [regression] Ensure YardMap gems have return type for Class<T>.new

* Handle self return-type-setting at lower level

* Fix bug where signature return type was based only on annotation

* Create implicit .new pins in namespace method queries (#853)

* Create implicit .new pins in namespace method queries

* Comment for Host#locate_pins exception

* Release 0.53.3

* Use logger in Solargraph::YardMap::Mapper spec

* Add support for simple block argument destructuring (#821)

* Add support for simple block argument destructuring

* Add spec for Array<Array(String, Integer)>#each

* Internal typechecking-driven annotations and code changes (#838)

* Internal typechecking-driven annotations and code changes

* Add @todo for predicate method return type issue

* Internal typechecking-driven annotations and code changes

* Benchmark the typecheck command (#852)

* Enable passing tests (#854)

* Send Gem Caching Progress Notifications to LSP Clients (#855)

* Send gem caching notifications

* LanguageServer::Progress

* DRY progress notifications

* Refactor

* added failing tests (#573)

* [breaking] Fix more complex_type_spec.rb cases (#813)

* [breaking] Fix more complex_type_spec.rb cases

* Consolidate the code that generates substrings to a single place
* Clean up more paths to pass through 'rooted' flag unchanged
* [breaking] Drop special-case interpretation of, e.g., `Array<(String)>` as
  'one element tuple' for future consistency with
  https://yardoc.org/types

  * (String) is a one element tuple in https://yardoc.org/types
  * <String> is an array of zero or more Strings in https://yardoc.org/types
  * Array<(String)> could be an Array of one-element tuples or a
    one element tuple.  https://yardoc.org/types treats it
    as the former.
  * Array<(String), Integer> is not ambiguous if we accept
    (String) as a tuple type, but not currently understood
    by Solargraph.

* Close out complex_type_spec @todos for better RBS output

* Simplify qualify() with transform()

* Resolve merge issue

* Mass assignment support - e.g., a, b = ['1', '2'] (#843)

* Memoize result of Chain#infer (#857)

* Memoize result of Chain#infer

* Add links to cache key

* Add node.location separately to cache key

https://github.com/whitequark/ast/blob/master/lib/ast/node.rb

https://github.com/whitequark/parser/blob/05b88aa0468ce29dfa21e1aff2f0506b1d5d82e1/lib/parser/ast/node.rb#L17

Parser::AST adds 'location' in Parser::AST::Node to its superclass
AST::Node, but doesn't overwrite the #hash and #eql? methods

* Fall back to using links.map(&:word)

* Implement eql? and hash for ApiMap for cache coherency

* Remove @cache from ApiMap#equality_fields

* Remove clip caches (#860)

* Add rbs_collection to maps (#858)

* Fix flaky rename specs (#869)

* Ignore malformed mixins and overloads (#862)

* Ignore malformed mixins

* Ignore malformed overload tags

* Add internal type annotations needed for strict-level typechecking (#865)

* Add internal type annotations needed for strict-level typechecking

* Fix annotations

* Add internal type annotations needed for strict-level typechecking

* Fix flaky rename specs

* Move to untyped as Hash value

---------

Co-authored-by: Fred Snyder <[email protected]>

* Drop Parser::ParserGem::ClassMethods#returns_from_node (#866)

* Refactor TypeChecker#argument_problems_for for type safety (#867)

* Refactor TypeChecker#argument_problems_for for type safety

This should put it in a state that it can pass type checking once we
have another feature or two

* Editor compatibility hack

* Fix class name

* Fix flaky rename specs

---------

Co-authored-by: Fred Snyder <[email protected]>

* Specify more type behavior for variable reassignment (#863)

* One-step source synchronization (#871)

* One-step source synchronization

* Synchronize libraries

* Fix progress notification timing (#873)

* Show cache progress in shell commands (#874)

* Show cache progress in shell commands

* Typecheck error

* Update spec/source_map/clip_spec.rb

* Resolve merge issues

* Update test expectations

* Update test expectations

* Fix merge issue

* Add regression test around assignment in return position

* Adjust spec expectations

* Fix merge

* Resolve merge issue

* Reduce use of ComplexType.parse() to preserve rooted? information (#870)

* [breaking] Fix more complex_type_spec.rb cases

* Consolidate the code that generates substrings to a single place
* Clean up more paths to pass through 'rooted' flag unchanged
* [breaking] Drop special-case interpretation of, e.g., `Array<(String)>` as
  'one element tuple' for future consistency with
  https://yardoc.org/types

  * (String) is a one element tuple in https://yardoc.org/types
  * <String> is an array of zero or more Strings in https://yardoc.org/types
  * Array<(String)> could be an Array of one-element tuples or a
    one element tuple.  https://yardoc.org/types treats it
    as the former.
  * Array<(String), Integer> is not ambiguous if we accept
    (String) as a tuple type, but not currently understood
    by Solargraph.

* Close out complex_type_spec @todos for better RBS output

* Simplify qualify() with transform()

* Reduce use of ComplexType.parse() to preserve rooted? information

* Make TypeMethods#rooted? more aggressive

* Fix flaky rename specs

* Reduce use of ComplexType.parse() to preserve rooted? information

* Reduce use of ComplexType.parse() to preserve rooted? information

* Fix merge issue

* Fix merge issue

* Use rooted_tag, remove two more parse() calls

* Preserve types in attr_accessor

* Reassure TypeMethods that implementers will have all_params

* Add regression test around assignment in return position

* Fix merge

* Separate the semantics of Type#rooted? and (new) Type#all_rooted?

* Test and fix issues keeping types from RBS input rooted

* Handle addiitional RBS types explicitly for type safety

---------

Co-authored-by: Fred Snyder <[email protected]>

* Ensure yield return types are qualified (#886)

* Ensure yield return types are qualified

* Add regression test around assignment in return position

* Understand type of 'def foo; @foo ||= bar; end' reader methods (#888)

* Improvements to #inspect output on pins and chains (#895)

* Remove redundant extend in Parser (#900)

* Remove redundant extend in Parser

* Update lib/solargraph/parser.rb

Co-authored-by: Vince Broz <[email protected]>

---------

Co-authored-by: Vince Broz <[email protected]>

* Block method resolution improvements (#885)

* Block method resolution improvements

* Add regression test around assignment in return position

* Fix merge issue

* Fix merge issue

* Understand mass assignment into instance variables (#893)

* Library sync and cache invalidation (#903)

* Library sync and cache invalidation

* Stop sleeping in catalog threads in mingw

* JIT library sync without threads

* MessageWorker prioritizes messages

* Unused instance variable

* JIT source parsing

* Fix JIT source parsing

* Avoid unnecessary parsing in library

* JIT source mapping

* Specs

* Stale code

* Library#map! finds external requires

* Preserve SourceMap#try_merge!

* Force catalog after caching gemspecs

* Synchronize count check in Library#sync_catalog

* Handle super and yield scenarios from blocks (#891)

* Handle super and yield scenarios from blocks

* Update spec/source_map/clip_spec.rb

Co-authored-by: Fred Snyder <[email protected]>

---------

Co-authored-by: Fred Snyder <[email protected]>

* Allow core and stdlib documentation to be uncached (#899)

* Allow core and stdlib documentation to be uncached

* Fix typo

* Surface variable names in documentation (#910)

* Surface variable names in documentation

* Documentation

* Keep idle progress notifications alive (#911)

* Release 0.54.1

* Release 0.54.1 patch: remove mutex from Library sync_count check

* Resolve generics correctly on mixin inclusion (#898)

* Resolve generics correctly on mixin inclusion

* Reduce expectations pending merge of another fix

* Fix merge issue

* Add alias-related regression test that now passes

* Method alias fixes

* Ensure method aliases are processed with resolve_generics()
* Avoid an extra hop in get_methods() resulting in no alias resolution

* Resolve merge issue

* Pick correct String#split overload (#905)

* Pick correct String#split overload

* Look for parameter types in superclasses too when resolving overloads
* Look at all unique types on parameters when resolving overloads

* Add @sg-ignore

* Fix type sent into YARD method (#912)

While it declares itself wanting a String, in reality the YARD method
takes #to_s, so this change just squashes a typechecking warning

* Early CancelRequest handling (#914)

* Destructure partial yield types (#915)

* Dependency versions (#916)

* Release 0.54.2

* Generic superclasses and defaulted type parameters via RBS

Enables scenarios using typed Array<A | B |C> methods from Array(A, B, C)

* Fix qualify_superclass's treatment of namespaces vs tags

* Render string literals from RBS in a useful way

* Treat literal nil as NilClass for method resolution and vice versa

Apply same for true/TrueClass and false/FalseClass

* Fix merge issue

* Fix merge issue

---------

Co-authored-by: Fred Snyder <[email protected]>
Co-authored-by: BonitaTerror <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant