Coder Social home page Coder Social logo

Comments (5)

bwilkerson avatar bwilkerson commented on July 21, 2024

@DanTup

from sdk.

hauserx avatar hauserx commented on July 21, 2024

Some quick debugging shows that there are no drivers in driversMap when empty data[] is returned, but there is driver when it starts to show up:

var drivers = driverMap.values.toList();

from sdk.

DanTup avatar DanTup commented on July 21, 2024

Creating the analysis roots is async, so at the time the request is being handled they probably haven't been set up yet.

Probably the fix will be something like changing this direct call to server.getResolvedUnit():

var result = await server.getResolvedUnit(path);

To instead use requireResolvedUnit which wraps it, but in the case where context roots are being set up, will wait for them to complete:

/// Attempts to get a [ResolvedUnitResult] for [path] or an error.
///
/// When [waitForInProgressContextRebuilds] is `true` and the file appears to
/// not be analyzed but analysis roots are currently being discovered, will
/// wait for discovery to complete and then try again (once) to get a result.
Future<ErrorOr<ResolvedUnitResult>> requireResolvedUnit(
String path, {
bool waitForInProgressContextRebuilds = true,
}) async {

That method treats errors slightly differently though so it might need a little tweaking to ensure requests for semantic tokens for non-Dart files or files that legitimately aren't analyzed are handled correctly.

from sdk.

hauserx avatar hauserx commented on July 21, 2024

Indeed this dirty fix helped. Thanks! (not sure how to make it better so that it can be merged, so just leaving here for now).

diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_semantic_tokens.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_semantic_tokens.dart
index 1a0e4da212d..740df9aaea5 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_semantic_tokens.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_semantic_tokens.dart
@@ -32,8 +32,11 @@ abstract class AbstractSemanticTokensHandler<T>

   Future<List<SemanticTokenInfo>> getServerResult(
       String path, SourceRange? range) async {
-    var result = await server.getResolvedUnit(path);
-    var unit = result?.unit;
+    var result = await requireResolvedUnit(path);
+    if (result.isError) {
+        return [];
+    }
+    var unit = result.resultOrNull?.unit;
     if (unit != null) {
       var computer = DartUnitHighlightsComputer(unit, range: range);
       return computer.computeSemanticTokens();

from sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.