<p>I'm implementing the Language Server Protocol (LSP) for my language, and I'm having huge problems tracking updated definitions.</p>
<h2>1. How to determine which files have been changed?</h2>
<p>lsp can only monitor whether there are file changes through <code>inotify</code> when it starts.</p>
<p>If the user does not use this editor (such as vscode), but uses other editors (such as Notepad), then this part of the code will cause dirty definitions. The file will not be fixed until the next time vscode opens it</p>
<p>If the user deletes this file using <code>os</code>, it will be even more serious. These definitions become ghost definitions.</p>
<h2>2. How to accurately update only the definition of changes</h2>
<p>I cache all definitions by filename, and fully refresh type definitions, trait definitions, file definitions, etc. when the file is updated.</p>
<p>Although this is a background operation that will not cause front-end lag, it will still make automatic completion quite slow.</p>
<p>Is there a way to accurately update a changed definition and all indirect definitions that reference it?</p>
<p><sub>I heard that rendering will also have the same needs, it seems that we can learn from it?</sub></p>

<language-server-protocol>
How to detect changes to definitions and their impacts?
# How to detect changes to definitions and their impacts?
Posted by: username_0 on 2023-11-28
I'm implementing the Language Server Protocol (LSP) for my language, and I'm having huge problems tracking updated definitions.

## 1. How to determine which files have been changed?

lsp can only monitor whether there are file changes through `inotify` when it starts.

If the user does not use this editor (such as vscode), but uses other editors (such as Notepad), then this part of the code will cause dirty definitions. The file will not be fixed until the next time vscode opens it

If the user deletes this file using `os`, it will be even more serious. These definitions become ghost definitions.

## 2. How to accurately update only the definition of changes

I cache all definitions by filename, and fully refresh type definitions, trait definitions, file definitions, etc. when the file is updated.

Although this is a background operation that will not cause front-end lag, it will still make automatic completion quite slow.

Is there a way to accurately update a changed definition and all indirect definitions that reference it?

I heard that rendering will also have the same needs, it seems that we can learn from it?
**Tags:** language-server-protocol
---
## 0 answers
