Comments (8)
It is a bug.
We trigger multiple lsp_apply_document_edit
commands at the same time, here ->
Lines 261 to 265 in cd7cb68
So when the edits for the first one is applied,
the second one will fail with the error LSP: ignoring edit due to non-matching document version
,
because the view.count
changed.
Line 56 in cd7cb68
Request
{
"context": {
"diagnostics": [
{
"code": 2304,
"message": "Cannot find name 'useState'.",
"range": {"end": {"character": 20, "line": 18 }, "start": {"character": 12, "line": 18 } },
"severity": 1,
"source": "typescript",
"tags": []
},
{
"code": 6133,
"message": "'d' is declared but its value is never read.",
"range": {"end": {"character": 9, "line": 18 }, "start": {"character": 8, "line": 18 } },
"severity": 4,
"source": "typescript",
"tags": [1]
}
],
"only": [
"source.addMissingImports.ts",
"source.organizeImports.ts"
],
"triggerKind": 2
},
"range": {"end": {"character": 0, "line": 113 }, "start": {"character": 0, "line": 0 } },
"textDocument": {
"uri": "file:///Users/predrag/Documents/work/pravoslavnaknjizara/appAdmin/src/pages/OrdersPage/OrdersPage.tsx"
}
}
{
"context": {
"diagnostics": [
{
"code": 2304,
"message": "Cannot find name 'useState'.",
"range": {"end": {"character": 20, "line": 18 }, "start": {"character": 12, "line": 18 } },
"severity": 1,
"source": "typescript",
"tags": []
},
{
"code": 6133,
"message": "'d' is declared but its value is never read.",
"range": {"end": {"character": 9, "line": 18 }, "start": {"character": 8, "line": 18 } },
"severity": 4,
"source": "typescript",
"tags": [1]
}
],
"only": [
"source.addMissingImports.ts",
"source.organizeImports.ts"
],
"triggerKind": 2
},
"range": {"end": {"character": 0, "line": 113 }, "start": {"character": 0, "line": 0 } },
"textDocument": {
"uri": "file:///Users/predrag/Documents/work/pravoslavnaknjizara/appAdmin/src/pages/OrdersPage/OrdersPage.tsx"
}
}
Response
[
{
"edit": {
"documentChanges": [
{
"edits": [
{
"newText": "import { DataNotFound } from \"@/components/NotDataFound/NotDataFound\"\nimport { SomethingBadHappen } from \"@/components/SomethingBadHappen/SomethingBadHappen\"\nimport { TopBar } from \"@/components/TopBar/TopBar\"\nimport { fets } from \"@/http\"\nimport { orderStatusToLabel } from \"@/utils/orderStatusLabels\"\nimport { useScrollToTop } from \"@/utils/useScrollToTop\"\nimport { Input, Pagination, ScrollShadow, Tab, Tabs } from \"@nextui-org/react\"\nimport { OrderStatus } from \"@shared/utils/applicationWideConstants\"\nimport { useDebounce } from \"@shared/utils/hooks/useDebounce\"\nimport { useNoInitialEffect } from \"@shared/utils/hooks/useNoInitialEffect\"\nimport { usePagination } from \"@shared/utils/hooks/usePagination\"\nimport { useQueryParam } from \"@shared/utils/hooks/useQueryParams\"\nimport { keepPreviousData, useQuery } from \"@tanstack/react-query\"\nimport { AnimatePresence, motion } from \"framer-motion\"\nimport { Search } from \"lucide-react\"\nimport { OrderItem } from \"./components/OrderItem\"\n",
"range": {
"end": {
"character": 0,
"line": 1
},
"start": {
"character": 0,
"line": 0
}
}
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 2 }, "start": {"character": 0, "line": 1 } } },
{
"newText": "",
"range": {"end": {"character": 0, "line": 3 }, "start": {"character": 0, "line": 2 }
}
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 4 }, "start": {"character": 0, "line": 3 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 5 }, "start": {"character": 0, "line": 4 }
}
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 6 }, "start": {"character": 0, "line": 5 }
}
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 7 }, "start": {"character": 0, "line": 6 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 8 }, "start": {"character": 0, "line": 7 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 9 }, "start": {"character": 0, "line": 8 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 10 }, "start": {"character": 0, "line": 9 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 11 }, "start": {"character": 0, "line": 10 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 12 }, "start": {"character": 0, "line": 11 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 13 }, "start": {"character": 0, "line": 12 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 14 }, "start": {"character": 0, "line": 13 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 15 }, "start": {"character": 0, "line": 14 } }
},
{
"newText": "",
"range": {"end": {"character": 0, "line": 16 }, "start": {"character": 0, "line": 15 } }
}
],
"textDocument": {
"uri": "file:///Users/predrag/Documents/work/pravoslavnaknjizara/appAdmin/src/pages/OrdersPage/OrdersPage.tsx",
"version": 192
}
}
]
},
"kind": "source.organizeImports.ts",
"title": "Organize Imports"
},
{
"edit": {
"documentChanges": [
{
"edits": [
{
"newText": "import { useState } from \"react\"\n",
"range": {"end": {"character": 0, "line": 16 }, "start": {"character": 0, "line": 16 } }
}
],
"textDocument": {
"uri": "file:///Users/predrag/Documents/work/pravoslavnaknjizara/appAdmin/src/pages/OrdersPage/OrdersPage.tsx",
"version": 192
}
}
]
},
"kind": "source.addMissingImports.ts",
"title": "Add all missing imports"
}
]
from lsp.
Also noticed something else. If I have source.removeUnused
enabled, it only removes some bad imports, in weird ways. In the same App.tsx file:
import { useCallback, useState } from "react";
import reactLogo from "./assets/react.svg";
import viteLogo from "/vite.svg";
useCallback, reactLogo and viteLogo are not needed. I experience the same problem of save-after-typing, even when removeUnused
is the only action, but also:
If I use removeUnused
AND organizeImports
together on save, nothing will get removed at all, no matter what. UNLESS I manually delete the reactLogo and viteLogo import lines; then, the useCallback
will get deleted appropriately.
With all of these issues, order of the actions does not seem to matter.
from lsp.
I'm not sure if something changed, but I've discovered that addMissingImports
never works as long as organizeImports
is enabled. I think it might be because the changes from both of these actions are batched; they affect the same lines, so, somehow the end state is that nothing gets changed?
Logs:
:: [19:53:49.360] --> LSP-typescript textDocument/codeAction (17): {'textDocument': {'uri': 'file:///home/d/react/todo/src/App.tsx'}, 'range': {'start': {'line': 0, 'character': 0}, 'end': {'line': 87, 'character': 0}}, 'context': {'diagnostics': [{'range': {'start': {'line': 48, 'character': 4}, 'end': {'line': 48, 'character': 12}}, 'message': "Cannot find name 'TodoList'.", 'severity': 1, 'code': 2304, 'source': 'typescript', 'tags': []}], 'triggerKind': <CodeActionTriggerKind.Automatic: 2>, 'only': ['source.fixAll.ts', 'source.addMissingImports.ts', 'source.organizeImports.ts']}}
:: [19:53:49.360] --> LSP-eslint textDocument/codeAction (2): {'textDocument': {'uri': 'file:///home/d/react/todo/src/App.tsx'}, 'range': {'start': {'line': 0, 'character': 0}, 'end': {'line': 87, 'character': 0}}, 'context': {'diagnostics': [], 'triggerKind': <CodeActionTriggerKind.Automatic: 2>, 'only': ['source.fixAll.eslint']}}
:: [19:53:49.371] <<< LSP-eslint (2) (duration: 10ms): []
:: [19:53:49.411] <<< LSP-typescript (17) (duration: 51ms): [{'title': 'Organize Imports', 'edit': {'documentChanges': [{'textDocument': {'uri': 'file:///home/d/react/todo/src/App.tsx', 'version': 311}, 'edits': [{'range': {'start': {'line': 0, 'character': 0}, 'end': {'line': 1, 'character': 0}}, 'newText': 'import "@/App.css";\nimport Button from "@/components/Button";\nimport FilterButton from "@/components/FilterButton";\nimport SearchBox from "@/components/SearchBox";\nimport TodoFooter from "@/components/TodoFooter";\nimport { Filter, Todo } from "@/types";\nimport { useState } from "react";\n'}, {'range': {'start': {'line': 1, 'character': 0}, 'end': {'line': 2, 'character': 0}}, 'newText': ''}, {'range': {'start': {'line': 2, 'character': 0}, 'end': {'line': 3, 'character': 0}}, 'newText': ''}, {'range': {'start': {'line': 3, 'character': 0}, 'end': {'line': 4, 'character': 0}}, 'newText': ''}, {'range': {'start': {'line': 4, 'character': 0}, 'end': {'line': 5, 'character': 0}}, 'newText': ''}, {'range': {'start': {'line': 5, 'character': 0}, 'end': {'line': 6, 'character': 0}}, 'newText': ''}, {'range': {'start': {'line': 6, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'newText': ''}]}]}, 'kind': 'source.organizeImports.ts'}, {'title': 'Add all missing imports', 'edit': {'documentChanges': [{'textDocument': {'uri': 'file:///home/d/react/todo/src/App.tsx', 'version': 311}, 'edits': [{'range': {'start': {'line': 5, 'character': 0}, 'end': {'line': 5, 'character': 0}}, 'newText': 'import TodoList from "@/components/TodoList";\n'}]}]}, 'kind': 'source.addMissingImports.ts'}]
from lsp.
By the way, the workaround I'm using is
- Disable organizeImports on save
- Use the Sublime command pallete to organize imports on-demand
- Always wait ~1 second after editing before saving to ensure imports are added on save
from lsp.
That looks like a missed bug to me still from the Python 3.8 update. LSP tries to send the enum value object for the triggerKind instead of just the plain value. I guess there is a corresponding error message in the console that it's not JSON-serializable?
from lsp.
I enabled "log_debug": true
in my LSP settings but the only thing I see in my sublime console on save is:
LSP: ignoring edit due to non-matching document version
LSP: ignoring edit due to non-matching document version
If I can help debug this in some way, please let me know and I'd be glad to help.
from lsp.
I believe I said somewhere that vscode only sends at most one code action in the only
list per request. If so then the way to fix it should be to trigger as many requests as there are "fix on save code actions" specified.
from lsp.
closing as duplicate of #2421
from lsp.
Related Issues (20)
- Prepare for upgrade of bracex and wcmatch libraries HOT 6
- [Runtime Error] ModuleNotFoundError: No module named 'wcmatch' HOT 1
- Investigate why didSave notification is not sent if view closed immediately after saving
- Two alternative hover definitions provided: one on mouseover, the other upon keyboard shortcut HOT 6
- Not Working After 3.8 Upgrade HOT 3
- Discuss removal of some APIs HOT 3
- Allow LSP packages to customize format_completion HOT 1
- Support list of commands, provided by language servers HOT 5
- Syntax highlighting in popups, returned by 3rd party language server, not work HOT 9
- Package is not installable HOT 5
- MissingUriError: View has no URI HOT 1
- `websocket_server` installs a root logger
- Cannot install LSP on clean installation HOT 15
- Updated to LSP 2.1.0 leads to FileNotFoundError and no LSP HOT 4
- KeyError on file-watcher HOT 2
- Replace `Enum` object with it's scalar value in the LSP log panel? HOT 1
- Text selection in popups HOT 2
- Unable to open URI
- Provide `Transport` as parameter when invoking `plugin.on_post_start` HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lsp.