Comments (15)
I've tagged 6.14.0
from dev.
I see what you mean but I'm not a fan of how complex this makes the already rather messy types, for a rather obscure use case. I think you'll just have to use casts there for the time being.
from dev.
Note that the update
method is only called for typing or backspacing anyway, and it's not something that will give you all editor updates.
Would adding support for a map
method ((CompletionResult, Transaction) -> CompletionResult
) that is called for every transaction help you here? Completion result maintenance happens on the state level, so you still wouldn't get access to a view. But that doesn't seem like it should be necessary to begin with.
from dev.
I think a map method would solve problem (2) in a good way, yes!
As for problem (1), I don't think it would completely solve it, as we also need to know about any changes that happened during transactions while the async completion source is inflight (before it's responded with its completions).
A concrete example of this would be a multiplayer scenario, where:
- User A initiates a completion request from an async source
- User B, 2 lines above, inserts a newline character
- The completion source returns, and the options are displayed to User A
- We need to map the changes that happened from when the request was initiated to when the response came back, as the async source may not know about them, and would have returned stale positions.
This would be prior to changes that happen while the completions are available, which I think would be solved by your solution above.
Let me know if you have any questions about this.
from dev.
The autocompletion plugin is already tracking transactions that happen while the completion is being fetched, it would call map
for those as well.
from dev.
if that's the case, I think a map
method sounds like it could work. for a given completion source, provided via override
, we could track any changes applied during the pending
state via the map
method, then apply them to the results once the source returns, and then continue to apply changes from the map
method while the state is active
.
from dev.
Does attached patch look like it would work for you? I had to use ChangeDesc
, rather than the full transaction, to also make this work correctly for mapped setActiveEffect
effects.
from dev.
Yeah I just tried this out and I think it should work for what I need. I noticed in a situation where a user is typing:
"foo"
and a slow completion source is triggered after "f", and again after "oo", when the results for the "f" request are returned, map
is immediately called with the change that includes "oo", which seems like it will work perfectly.
If you're able to tag a release for this that would be great!
from dev.
Hm I just realized I might be more stumped by the ChangeDesc
than I originally thought. I can compose
the ChangeDesc
s togther to keep a "missed changes" desc, but I realized I need to do the following steps at the point where I want to apply one of the completion items:
- Invert the
ChangeDesc
- Use the inverted desc to get the original document state, at the starting point in time that the completion request was initiated
- Convert the LSP position to the document offset (LSP position is encoded as {line: number, column: number})
- Map that offset over the original
ChangeDesc
I realized that step 2 might not be possible with a ChangeDesc
and that I may need a ChangeSet
after all. Unless I'm just missing a series of manipulations that could let me get to the same end state...
from dev.
Ok i may have found a workaround by storing a copy of context.state.doc
before the request was initiated. That allows me to get past step #2.
from dev.
@marijnh would it be possible to include EditorState
or CompletionContext
as a third parameter in map
, similar to update
? I think that would help me solve my mapping problem (as I need the document to translate from LSP positions which are line/col and have no concept of absolute offset, to CM positions which are absolute and have no concept of line/col in change descs without the document itself)
I would try my hand at a PR but figured I'd ask if you think it's possible first - happy to try a PR if so.
from dev.
These are also called from a state effect map function, which itself has no effect to any editor state, so this would be difficult to do. Would it be possible to work in flat positions at this level by doing the conversion from line/col positions to flat positions at at an earlier point?
from dev.
Oh. Wait yeah I have access to the state at request time via the AutoCompletion Context, which means I have the starting doc, so I can transform the LSP response to the absolute offset in the starting doc, then map it over the change descs. Sorry I missed that idea yesterday. That should work. Will update if it doesn't. Thanks!
from dev.
Ok one more request - it would be nice if CompletionResult
was generic on Completion
. I've got some extra properties hanging off my Completion
objects:
class MyCompletionWithExtraProperties implements Completion {....}
It would be awesome if I could have those types in update
and map
methods for a completion source:
type CompletionSource = (context: CompletionContext) => CompletionResult | null | Promise<CompletionResult | null>;
something like
type CompletionSource = <C extends Completion = Completion>(context: CompletionContext) => CompletionResult<C> | null | Promise<CompletionResult<C> | null>;
async function completionSource(context) {
const options = [new MyCompletionWithExtraProperties(...)]
return {
from: context.pos,
options,
update: (current: CompletionResult, ...) => {
current.options; /* Completion[] */
// would be nice if `current.options` was typed as MyCompletionWithExtraProperties[]
...
},
map: (current: CompletionResult, ...) => {
// same...
},
}
}
from dev.
No worries thanks for working with me on some of these :)
from dev.
Related Issues (20)
- Linter example no longer works on Ubuntu 24.04? HOT 2
- Gboard doesn't delete text in Firefox HOT 7
- forceLinting() doesn't cancel pending linting HOT 5
- MergeView: crashes browser tab for large files HOT 2
- Built in browser search does not work for large documents HOT 3
- Scroll position shifts on click into the middle of a large document HOT 2
- Selection breaks if you drag outside of an iframe HOT 1
- Content not properly rendered when line contains many block widgets HOT 1
- CODE
- Xxx
- Codemirror/view 6.28.0 breaks newlines in chrome 126 HOT 8
- Selecting backwards throws errors with EditContext (6.28.0). HOT 4
- Setting `EditorView.editable.of(false)` does not work with EditContext API HOT 2
- After setting the error diagnostics by using setDiagnostics, when copying & pasting the complete text, the entire document prompts error. HOT 2
- placeholder with HTMLElement, when shared between multiple views, is only visible on one view
- codemirror/view 6.28.2 version will cause abnormal input of Chinese input method HOT 24
- python highlighting fails with initial blank line or comment HOT 4
- Programmatically fetch CodeMirror version HOT 1
- event `compositionstart ` was not triggered correctly HOT 3
- Getting "document is not defined" error on while our app loads CodeMirrorEditor HOT 5
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 dev.