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

feat: upgrade codemirror 5 to codemirror 6 #1510

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jczhong84
Copy link
Collaborator

Upgrade the query editor to use codemirror6, changes cover below editor features and most of them will have the same user experience

  • auto complete
  • linter
  • table hover
  • keymap
  • lint summary (use a new status bar at the bottom)
  • search highlighter
  • theme
  • full screen
  • selection run

some screenshots

linter error and summary status bar
image

table hover
image

auto complete
image

search highlight
image

Comment on lines +66 to +76
if (language && language in functionDocumentationByNameByLanguage) {
const functionDefs =
functionDocumentationByNameByLanguage[language];
const functionNameLower = (functionName || '').toLowerCase();

if (functionNameLower in functionDefs) {
return functionDefs[functionNameLower];
}
}

return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (language && language in functionDocumentationByNameByLanguage) {
const functionDefs =
functionDocumentationByNameByLanguage[language];
const functionNameLower = (functionName || '').toLowerCase();
if (functionNameLower in functionDefs) {
return functionDefs[functionNameLower];
}
}
return null;
const functionDefs = functionDocumentationByNameByLanguage?.[language];
const functionNameLower = (functionName || '').toLowerCase();
return functionDefs?.[functionNameLower];

Copy link
Collaborator

Choose a reason for hiding this comment

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

also useCallback is not needed with above code

}

if (lintSummary.numErrors + lintSummary.numWarnings > 0) {
return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

use span to be consistent

export const useAutoCompleteExtension = ({ view, autoCompleterRef }) => {
const [typing, setTyping] = useState(false);

const getCompletions = useCallback(async (context) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

import {CompletionContext} from "@codemirror/autocomplete"?

Comment on lines +33 to +48
if (tableInfo.line === line) {
const isSchemaExplicit =
tableInfo.end - tableInfo.start >
tableInfo.name.length;
const tablePos = {
from:
tableInfo.start +
(isSchemaExplicit
? tableInfo.schema.length
: 0),
to: tableInfo.end,
};

if (tablePos.from <= ch && tablePos.to >= ch) {
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (tableInfo.line === line) {
const isSchemaExplicit =
tableInfo.end - tableInfo.start >
tableInfo.name.length;
const tablePos = {
from:
tableInfo.start +
(isSchemaExplicit
? tableInfo.schema.length
: 0),
to: tableInfo.end,
};
if (tablePos.from <= ch && tablePos.to >= ch) {
return true;
}
if (tableInfo.line !== line) return false;
const isSchemaExplicit =
tableInfo.end - tableInfo.start >
tableInfo.name.length;
const tablePos = {
from:
tableInfo.start +
(isSchemaExplicit
? tableInfo.schema.length
: 0),
to: tableInfo.end,
};
return tablePos.from <= ch && tablePos.to >= ch;

Comment on lines +91 to +93
} else {
return null;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (!tooltipComponent) return null;

const lastPart = parts[parts.length - 1];

// Check if the last part is a single alphabetical character
if (lastPart.length === 1 && /[a-zA-Z]/.test(lastPart)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this just test [A-Z]?

import { isEqual } from 'lodash';
import { useEffect, useRef } from 'react';

export default function useDeepCompareEffect(callback, dependencies) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

add type to the parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants