-
Notifications
You must be signed in to change notification settings - Fork 6k
Reland "iOS spell-checker ObjC #32941" #34356
Conversation
FlutterSpellCheckPlugin* spellCheckPlugin = _spellCheckPlugin.get(); | ||
[_spellCheckChannel.get() | ||
setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { | ||
[spellCheckPlugin handleMethodCall:call result:result]; | ||
}]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the 3rd difference between the original PR, I moved the method channel setup out of FlutterSpellCheckPlugin
- (NSString*)toFormattedString { | ||
return FormatSpellCheckResult(_misspelledRange.location, | ||
_misspelledRange.location + _misspelledRange.length - 1, | ||
[_suggestions copy]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the 2nd different between the original PR. Instead of formatting the result as a dictionary in my original PR: https://github.com/flutter/engine/pull/32941/files#diff-1c2372162cba7041e14181d7d080cbb0c66eeb44e9cd75379ab8969646e3087bR154-R159
I formatted as a String that matches the android format: https://github.com/flutter/engine/blob/main/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java#L108-L110
Note that there is a typo in the android documentation, it is suppose to be \n not /n
// UITextChecker is an expensive object to initiate, see: | ||
// https://github.com/flutter/flutter/issues/104454. Lazily initialate the UITextChecker object | ||
// until at first method channel call. We avoid using lazy getter for testing. | ||
_textChecker = [[UITextChecker alloc] init]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1st difference between the original PR, the UITextChecker
object is initialized during the first method channel call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The laziness is typically implemented inside a property getter:
- textChecker {
if (!_textChecker)
_textChecker = ...
return _textChecker
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it would be hard to test. For example, if I want to test the textChecker
is nil at initialization, i couldn't because as soon as i call the getter, it is initialized.
My comment explained why we avoided a lazy getter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry i miss-read that part.
Adding @hellohuanlin as the reviewer as the reviewer of the original PR @jmagman is OOO. |
Gold has detected about 2 new digest(s) on patchset 3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main question is about whether to reinvent an in-house serialization format
|
||
// Spell check results will be encoded as a string representing the span of that result, with | ||
// the format "start_index.end_index.suggestion_1\nsuggestion_2\nsuggestion_3". | ||
static NSString* FormatSpellCheckResult(NSUInteger startIndex, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Is this the same format as the android?
- Why are we using a custom serialization? can we just use more standardized ones like JSON or CSV?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it is matching android, im not sure the detailed reason behind not using JSON.
cc @camsim99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason behind this was to avoid unnecessary overhead as brought up in my design doc. I think I discussed with @cyanglaz doing some testing to see if this would significantly slow things down and I would be open to that since that's the main concern!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camsim99 Are you worrying that JSON serialization/parsing is significantly slower (or taking more space) than the proposed custom format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think JSON is a better approach, it shouldn't be slower.
For example in java: https://stackoverflow.com/questions/12155800/how-to-convert-hashmap-to-json-object-in-java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought there was a discussion about this format when @camsim99 did the Android engine PR, but I couldn't find it (code in the PR). I think @GaryQian was involved if I remember right?
From my memory the concern with JSON was the repetition of keys for every suggestion, which for a long document there could be many.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is what I was thinking of from the design doc: https://docs.google.com/document/d/1AVI2dwpBYtvf7TnDyfLYuE8VLwoMj3iaRLUs3qMjxWY/edit?disco=AAAATKs1zrg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If memory is a concern, it seems to me that we should limit the misspelled word that the API returns.
If we write our own formatter and parser, we also have to consider the performance of them, which creates an additional maintenance burden.
Also, I was a little confused myself last week. JSON serialization is already supported by default on MethodChannel, so we don't really have to do an extra serialization in this PR if we choose to use JSON. I will revert that code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked to Gary a little bit and we agreed that using JSON seems to be the way to go for now. If it turns out to be slow, we can revisit using a custom format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Sounds like a solid plan!
|
||
// Get all the misspelled words and suggestions in the entire String. | ||
// | ||
// The result will be formatted as am NSArray. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an
// UITextChecker is an expensive object to initiate, see: | ||
// https://github.com/flutter/flutter/issues/104454. Lazily initialate the UITextChecker object | ||
// until at first method channel call. We avoid using lazy getter for testing. | ||
_textChecker = [[UITextChecker alloc] init]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The laziness is typically implemented inside a property getter:
- textChecker {
if (!_textChecker)
_textChecker = ...
return _textChecker
}
Gold has detected about 2 new digest(s) on patchset 5. |
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. |
0b5e6ce
to
c1c1f2c
Compare
@@ -0,0 +1 @@ | |||
import Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accedentialy checked this in, will remove
@hellohuanlin Updated the format to JSON, ptal cc @camsim99 |
Gold has detected about 1 new digest(s) on patchset 6. |
c2d5961
to
f2511d8
Compare
Revert "Revert "iOS spell-checker ObjC" (flutter#33570)" This reverts commit b1fafb9. method channel move out of plugin tests cleanup fix fix typo remove swift file change format to JSON nil error format revert format code
65d6824
to
8847696
Compare
Friendly ping @hellohuanlin I'm not sure about the skia-gold check. There is no bot message saying the gold is fixed but the gold error comment didn't show up after re-basing so I assume it was an upstream issue and re-base fixed it? cc @godofredoc Do you think we can improve the skia-gold bot so that it is clearer that the skia-gold issue is fixed after a commit? |
Things added to the original PR:
Part of flutter/flutter#34688
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.