(file)
| 722 | } |
| 723 | |
| 724 | async function configureLspForFile(file) { |
| 725 | const metadata = buildLspMetadata(file); |
| 726 | const token = ++lspRequestToken; |
| 727 | if (!metadata) { |
| 728 | detachActiveLsp(); |
| 729 | editor.dispatch({ effects: lspCompartment.reconfigure([]) }); |
| 730 | return; |
| 731 | } |
| 732 | if (metadata.uri !== lastLspUri) { |
| 733 | detachActiveLsp(); |
| 734 | } |
| 735 | try { |
| 736 | const extensions = |
| 737 | (await lspClientManager.getExtensionsForFile(metadata)) || []; |
| 738 | if (token !== lspRequestToken) return; |
| 739 | if (!extensions.length) { |
| 740 | lastLspUri = null; |
| 741 | editor.dispatch({ effects: lspCompartment.reconfigure([]) }); |
| 742 | return; |
| 743 | } |
| 744 | lastLspUri = metadata.uri; |
| 745 | editor.dispatch({ |
| 746 | effects: lspCompartment.reconfigure(extensions), |
| 747 | }); |
| 748 | } catch (error) { |
| 749 | if (token !== lspRequestToken) return; |
| 750 | console.error("Failed to configure LSP", error); |
| 751 | lastLspUri = null; |
| 752 | editor.dispatch({ effects: lspCompartment.reconfigure([]) }); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | function detachLspForFile(file) { |
| 757 | if (!file || file.type !== "editor") return; |
no test coverage detected