Skip to content

Stale compilation diagnostics #2691

@harpocrates

Description

@harpocrates

This project is using Scala 2.12.17, with a manually constructed Bloop config. This same config and same project have been working completely fine, but just now I ran into a case of Metals reporting stale compilation diagnostics. Conveniently, I did not have any other working changes - this was almost just a fresh pull of a project that compiles. The sequence of steps I took

  1. move a file MyClass.scala from org.pkg1 to org.pkg1.nested (I dragged the file across folders reflecting the package structure)
  2. I asked Metals to show me the refactor it was proposing and then accepted it. The refactor did the following (which seems right to me):
    • updated the package header line in MyClass.scala
    • added some import org.pkg1.nested.MyClass imports in two places where MyClass was being used and previously imported via import org.pkg1._
  3. I saved MyClass.scala which was currently open. Then, when I saw the diagnostics in problems pane did not go away, I ran save all and saved the other two files where imports had been changed.

This is when I noticed that the problems in the diagnostics pane were showing something wrong: they were both pointing to the newly added import lines and they both said:

object MyClass is not a member of package org.pkg1.nested.MyClass

Here's an excerpt from bsp.trace.json which shows a number of small compile requests came in:

Redacted BSP logs
// I re-opened the project here, but I think it was previously compiling.

[Trace - 01:45:01 PM] Sending request 'buildTarget/compile - (20)'
Params: {
  "targets": [
    {
      "uri": "..."
    }
  ],
  "originId": "METALS-$e0a3f881-c18f-4134-bb81-e588d979062a",
  "arguments": [
    "--best-effort"
  ]
}

[Trace - 01:45:01 PM] Received notification 'build/publishDiagnostics'
// Just an expected warning about something unused

[Trace - 01:45:01 PM] Received response 'buildTarget/compile - (20)' in 325ms
Result: {
  "originId": "METALS-$e0a3f881-c18f-4134-bb81-e588d979062a",
  "statusCode": 1
}

[Trace - 01:45:32 PM] Sending request 'buildTarget/compile - (25)'
Params: {
  "targets": [
    {
      "uri": "..."
    }
  ],
  "originId": "METALS-$69ee1c10-b105-47b5-bb07-8c0ddd2b90a3",
  "arguments": [
    "--best-effort"
  ]
}


[Trace - 01:45:32 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "1"
  },
  "eventTime": 1750614332419,
  "message": "Compiling MyProject (3 Scala sources)",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "..."
    }
  }
}

// ... lots of `taskProgress`% updates


[Trace - 01:45:36 PM] Received notification 'build/logMessage'
Params: {
  "type": 3,
  "message": "sbt-api: Unhandled method type class MyClass in package pkg1"
}

// This error also normally shows up when compiling the project. Not sure if it is related. A bit surprising to see the old package...
[Trace - 01:45:36 PM] Received notification 'build/logMessage'
Params: {
  "type": 3,
  "message": "sbt-api: Unhandled method type class MyClass in package pkg1"
}

// ... lots of `taskProgress` % updates

[Trace - 01:45:36 PM] Received notification 'build/taskProgress'
// Compiling MyProject (100%)

[Trace - 01:45:37 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "1"
  },
  "eventTime": 1750614337336,
  "message": "Compiled \u0027MyProject\u0027",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "..."
    },
    "originId": "METALS-$69ee1c10-b105-47b5-bb07-8c0ddd2b90a3",
    "errors": 0,
    "warnings": 0,
    "isNoOp": false,
    "isLastCycle": true,
    "clientDir": "file:///tmp/MyProject_repl2/MyProject/bloop-bsp-clients-classes/classes-Metals-tXzjuzmoRhCar8MfQrhzWg\u003d\u003d/",
    "analysisOut": "file:///tmp/MyProject_repl2/MyProject/MyProject-analysis.bin"
  }
}

[Trace - 01:45:37 PM] Received response 'buildTarget/compile - (25)' in 5027ms
Result: {
  "originId": "METALS-$69ee1c10-b105-47b5-bb07-8c0ddd2b90a3",
  "statusCode": 1
}
Error: null


[Trace - 01:45:37 PM] Sending request 'buildTarget/compile - (28)'
Params: {
  "targets": [
    {
      "uri": "..."
    }
  ],
  "originId": "METALS-$5c41feef-467b-4254-8916-2831592d1db9",
  "arguments": [
    "--best-effort"
  ]
}

[Trace - 01:45:37 PM] Received response 'buildTarget/compile - (28)' in 194ms
Result: {
  "originId": "METALS-$5c41feef-467b-4254-8916-2831592d1db9",
  "statusCode": 1
}
Error: null

[Trace - 01:45:40 PM] Sending request 'buildTarget/compile - (31)'
Params: {
  "targets": [
    {
      "uri": "..."
    }
  ],
  "originId": "METALS-$e54189e3-5953-4138-a54d-f0cce98c7c4c",
  "arguments": [
    "--best-effort"
  ]
}

[Trace - 01:45:41 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "2"
  },
  "eventTime": 1750614341102,
  "message": "Compiling MyProject (2 Scala sources)",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "..."
    }
  }
}

// ... lots of `taskProgress`% updates

[Trace - 01:45:41 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "File1.scala"
  },
  "buildTarget": {
    "uri": "..."
  },
  "originId": "METALS-$e54189e3-5953-4138-a54d-f0cce98c7c4c",
  "diagnostics": [
    {
      "range": {
        ...
      },
      "severity": 1,
      "source": "bloop",
      "message": "object MyClass is not a member of package org.pkg1.nested.MyClass",
      "data": {
        "actions": []
      }
    }
  ],
  "reset": true
}

[Trace - 01:45:41 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "File2.scala"
  },
  "buildTarget": {
    "uri": "..."
  },
  "originId": "METALS-$e54189e3-5953-4138-a54d-f0cce98c7c4c",
  "diagnostics": [
    {
      "range": {
        ...
      },
      "severity": 1,
      "source": "bloop",
      "message": "object MyClass is not a member of package org.pkg1.nested.MyClass",
      "data": {
        "actions": []
      }
    }
  ],
  "reset": true
}

[Trace - 01:45:43 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "2"
  },
  "eventTime": 1750614343071,
  "message": "Compiled \u0027MyProject\u0027",
  "status": 2,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "..."
    },
    "originId": "METALS-$e54189e3-5953-4138-a54d-f0cce98c7c4c",
    "errors": 2,
    "warnings": 0,
    "isNoOp": false,
    "isLastCycle": true
  }
}


[Trace - 01:45:43 PM] Received response 'buildTarget/compile - (31)' in 2103ms
Result: {
  "originId": "METALS-$e54189e3-5953-4138-a54d-f0cce98c7c4c",
  "statusCode": 2
}
Error: null

[Trace - 01:45:43 PM] Sending request 'buildTarget/compile - (34)'
Params: {
  "targets": [
    {
      "uri": "..."
    }
  ],
  "originId": "METALS-$135b5282-b7e0-4d97-9cbd-07f4ea1e4db4",
  "arguments": [
    "--best-effort"
  ]
}

[Trace - 01:45:43 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "3"
  },
  "eventTime": 1750614343178,
  "message": "Compiling MyProject (2 Scala sources)",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "..."
    }
  }
}

[Trace - 01:45:43 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "File1.scala"
  },
  "buildTarget": {
    "uri": "..."
  },
  "originId": "METALS-$135b5282-b7e0-4d97-9cbd-07f4ea1e4db4",
  "diagnostics": [
    {
      "range": {
        "start": {
          "line": 16,
          "character": 0
        },
        "end": {
          "line": 16,
          "character": 77
        }
      },
      "severity": 1,
      "source": "bloop",
      "message": "object MyClass is not a member of package org.pkg1.nested.MyClass",
      "data": {
        "actions": []
      }
    }
  ],
  "reset": true
}


[Trace - 01:45:43 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "File2.Simulate.scala"
  },
  "buildTarget": {
    "uri": "..."
  },
  "originId": "METALS-$135b5282-b7e0-4d97-9cbd-07f4ea1e4db4",
  "diagnostics": [
    {
      "range": {
        "start": {
          "line": 23,
          "character": 0
        },
        "end": {
          "line": 23,
          "character": 77
        }
      },
      "severity": 1,
      "source": "bloop",
      "message": "object MyClass is not a member of package org.pkg1.nested.MyClass",
      "data": {
        "actions": []
      }
    }
  ],
  "reset": true
}

[Trace - 01:45:45 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "3"
  },
  "eventTime": 1750614345132,
  "message": "Compiled \u0027MyProject\u0027",
  "status": 2,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "..."
    },
    "originId": "METALS-$135b5282-b7e0-4d97-9cbd-07f4ea1e4db4",
    "errors": 2,
    "warnings": 0,
    "isNoOp": false,
    "isLastCycle": true
  }
}


[Trace - 01:45:45 PM] Received response 'buildTarget/compile - (34)' in 2043ms
Result: {
  "originId": "METALS-$135b5282-b7e0-4d97-9cbd-07f4ea1e4db4",
  "statusCode": 2
}
Error: null

I'm not sure whether it is expected or not given that the latest compilation did not succeed, but the source hashes in the analysis.bin file do not match what I get manually computing the hashes for the 3 files that changed... I've stowed away the entire output directory for safe-keeping.

One other complicating factor: there is a second Bloop client also connected for this same project, but it has not been issuing any build requests. Only requests it would've been making are workspace/buildTargets calls (just as a healthcheck for the connection working).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA defect or misbehaviour.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions