Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeEditor: Ensure suggestions only apply to the instance of the editor that registered them #69995

Merged
merged 6 commits into from Jun 14, 2023

Conversation

ashharrison90
Copy link
Contributor

What is this feature?

  • passes the modelId when registering suggestions
    • this ensures that future calls to provideCompletionItems can check the modelId against the registered modelId
      • if they match -> great, show suggestions
      • if they don't -> don't show these suggestions

Why do we need this feature?

  • so suggestions don't bleed between editor instances/are duplicated

Who is this feature for?

  • anyone using CodeEditor

Which issue(s) does this PR fix?:

Fixes #69262

Special notes for your reviewer:

i tried to look for a way to write a test that would prevent regressions to this... but i don't think it's possible in react-testing-library 😬

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

ashharrison90 and others added 5 commits June 13, 2023 10:06
lastFile:packages/grafana-ui/src/components/Monaco/CodeEditor.internal.story.tsx
lastFile:packages/grafana-ui/src/components/Monaco/suggestions.ts
lastFile:packages/grafana-ui/src/components/Monaco/CodeEditor.internal.story.tsx
lastFile:packages/grafana-ui/src/components/Monaco/suggestions.ts
@ashharrison90 ashharrison90 added this to the 10.0.x milestone Jun 13, 2023
@ashharrison90 ashharrison90 self-assigned this Jun 13, 2023
@ashharrison90 ashharrison90 requested a review from a team as a code owner June 13, 2023 11:41
@ashharrison90 ashharrison90 requested review from tskarhed and L-M-K-B and removed request for a team June 13, 2023 11:41
@ashharrison90 ashharrison90 added area/frontend/code-editor mob session Something solved during a mob session labels Jun 13, 2023
Copy link
Contributor

@tskarhed tskarhed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: No tests for this one then 😢

Comment on lines -90 to -92
if (getSuggestions) {
this.completionCancel = registerSuggestions(monaco, language, getSuggestions);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the logical difference ebtween doing this onMount instead of beforeMount?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it will happen slightly later, but by doing it onMount we get access to the editor instance, whereas before mount we only have access to the global monaco instance


this.modelId = editor.getModel()?.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't require a URI? 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, i think because the model is associated with this editor (as opposed to getting it from the global monaco namespace)

@ashharrison90 ashharrison90 merged commit 61dbad6 into main Jun 14, 2023
16 checks passed
@ashharrison90 ashharrison90 deleted the ue-code-editor branch June 14, 2023 12:51
@grafanabot
Copy link
Contributor

The backport to v10.0.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-69995-to-v10.0.x origin/v10.0.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 61dbad6905264e41e9464032f065993fb50cf4ea
# When the conflicts are resolved, stage and commit the changes
git add . && git commit --no-edit
# Push it to GitHub
git push --set-upstream origin backport-69995-to-v10.0.x
git switch main
# Remove the local backport branch
git branch -D backport-69995-to-v10.0.x

Then, create a pull request where the base branch is v10.0.x and the compare/head branch is backport-69995-to-v10.0.x.

@grafanabot grafanabot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Jun 14, 2023
ashharrison90 added a commit that referenced this pull request Jun 14, 2023
…or that registered them (#69995)

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/CodeEditor.internal.story.tsx

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/suggestions.ts

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/CodeEditor.internal.story.tsx

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/suggestions.ts

* remove duplicate editor from story

* remove suggestions from story

---------

Co-authored-by: Laura Benz <laura.benz@grafana.com>
Co-authored-by: Tobias Skarhed <tobias.skarhed@gmail.com>
(cherry picked from commit 61dbad6)

# Conflicts:
#	packages/grafana-ui/src/components/Monaco/CodeEditor.tsx
ashharrison90 added a commit that referenced this pull request Jun 14, 2023
#70067)

CodeEditor: Ensure suggestions only apply to the instance of the editor that registered them (#69995)

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/CodeEditor.internal.story.tsx

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/suggestions.ts

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/CodeEditor.internal.story.tsx

* user essentials mob! 🔱

lastFile:packages/grafana-ui/src/components/Monaco/suggestions.ts

* remove duplicate editor from story

* remove suggestions from story

---------

Co-authored-by: Laura Benz <laura.benz@grafana.com>
Co-authored-by: Tobias Skarhed <tobias.skarhed@gmail.com>
(cherry picked from commit 61dbad6)

# Conflicts:
#	packages/grafana-ui/src/components/Monaco/CodeEditor.tsx
@zerok zerok modified the milestones: 10.0.x, 10.0.1 Jun 20, 2023
@zerok zerok added this to the 10.1.x milestone Jun 21, 2023
@ricky-undeadcoders ricky-undeadcoders modified the milestones: 10.1.x, 10.1.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend/code-editor area/frontend backport v10.0.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. mob session Something solved during a mob session type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GrafanaUI: CodeEditor shows duplicate suggestions
6 participants