langium icon indicating copy to clipboard operation
langium copied to clipboard

Cancellation: More Problems

Open cdietrich opened this issue 1 year ago • 3 comments

From https://github.com/eclipse-langium/langium/discussions/1562 and https://github.com/eclipse-langium/langium/pull/1566

Additionally to the missing notifications to the client we see more problems with cancellation respectively the recovery from it.

  • shouldRelink / unlink evaluates document.references only. but this wont be maintained if the document did not enter the linking phase before the cancellation, but during the linking of another document some references in that document are resolved in this document
  • changed files are just invalidated, but not unlinked, which leads to the same problem, as reparse might be skipped if content has not changed.

To be investigated: at end of iterative deletes, not all delete validations seems to be have sent to the client

cdietrich avatar Jul 02 '24 10:07 cdietrich

workaround ideas:

override invalidateDocument(uri: URI): LangiumDocument | undefined {
    const result = super.invalidateDocument(uri)
    if (result !== undefined) {
      for (const node of AstUtils.streamAst(result.parseResult.value)) {
        AstUtils.streamReferences(node).forEach(refInfo => {
          const ref = refInfo.reference as DefaultReference
          if (ref._ref !== undefined) {
            delete ref._ref
            delete ref._nodeDescription
          }
        })
      }
    }
    return result
  }
protected override shouldRelink(document: LangiumDocument, changedUris: Set<string>): boolean {
    let result = super.shouldRelink(document, changedUris)

    if (!result) {
      for (const node of AstUtils.streamAst(document.parseResult.value)) {
        AstUtils.streamReferences(node).forEach(refInfo => {
          const ref = refInfo.reference as DefaultReference
          if (ref._ref !== undefined) {
            if (isLinkingError(ref._ref)) {
              result = true
            }
          }
        })
      }
    }
    return result
  }
override unlink(document: LangiumDocument): void {
    super.unlink(document)
    for (const node of AstUtils.streamAst(document.parseResult.value)) {
      AstUtils.streamReferences(node).forEach(refInfo => {
        const ref = refInfo.reference as DefaultReference
        if (ref._ref !== undefined) {
          delete ref._ref
          delete ref._nodeDescription
        }
      })
    }
  }

cdietrich avatar Jul 02 '24 10:07 cdietrich

here is my attempts to reproduce the delete problem

https://github.com/eclipse-langium/langium/compare/main...cdietrich:langium:cd-repro2

but with longer timeouts it works....

cdietrich avatar Jul 02 '24 13:07 cdietrich

it looks like the delete problem might be a client side one. i dont always see all deletes arrive at the server.

cdietrich avatar Jul 02 '24 17:07 cdietrich

created https://github.com/microsoft/vscode-languageserver-node/issues/1503 for the client side clarification

cdietrich avatar Jul 03 '24 04:07 cdietrich

Has been fixed with https://github.com/eclipse-langium/langium/pull/1566. Release is available at [email protected].

msujew avatar Jul 04 '24 10:07 msujew