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: playground phase 3 #11

Merged
merged 6 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"dependencies": {
"@tidbcloud/tisqleditor-extension-basic-setup": "workspace:^",
"@tidbcloud/tisqleditor-extension-cur-sql": "workspace:^",
"@tidbcloud/tisqleditor-extension-lang-sql": "workspace:^",
"@tidbcloud/tisqleditor-extension-sql-parser": "workspace:^"
}
}
16 changes: 12 additions & 4 deletions packages/core/src/editor-instance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SQLConfig } from '@codemirror/lang-sql'
import { search } from '@codemirror/search'
import { Compartment, EditorState, Extension } from '@codemirror/state'
import { EditorView } from '@codemirror/view'
import { Compartment, EditorState, Extension } from '@codemirror/state'
import { SQLConfig, sql, MySQL } from '@codemirror/lang-sql'
import { search } from '@codemirror/search'

import {
BasicSetupOptions,
Expand All @@ -12,12 +12,18 @@ import {
getSqlStatements,
getNearbyStatement
} from '@tidbcloud/tisqleditor-extension-sql-parser'
import { langSql } from '@tidbcloud/tisqleditor-extension-lang-sql'
import {
curSql,
getCurStatements
} from '@tidbcloud/tisqleditor-extension-cur-sql'

const langSql = (config: SQLConfig) =>
sql({
dialect: MySQL,
upperCaseKeywords: true,
...config
})

export class SQLEditorInstance {
constructor(
public editorId: string,
Expand Down Expand Up @@ -100,8 +106,10 @@ export const createSQLEditorInstance = ({
search({
top: true
}),

themeCompartment.of(theme),
sqlCompartment.of(langSql(sqlConfig)),

sqlParser(),
curSql(),

Expand Down
21 changes: 13 additions & 8 deletions packages/extensions/autocomplete/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EditorState } from '@codemirror/state'
import { EditorView, Rect, keymap } from '@codemirror/view'
import {
acceptCompletion,
autocompletion,
Expand All @@ -6,8 +8,7 @@ import {
CompletionSource
} from '@codemirror/autocomplete'
import { indentLess, indentMore } from '@codemirror/commands'
import { EditorState } from '@codemirror/state'
import { EditorView, Rect, keymap } from '@codemirror/view'

import {
Brackets,
Calendar,
Expand Down Expand Up @@ -203,9 +204,12 @@ const baseTheme = EditorView.baseTheme({
color: '#333333'
}
},
'.cm-autocomplete-item > img': {
marginRight: '10px',
verticalAlign: 'middle'
'.cm-autocomplete-item': {
display: 'flex',
alignItems: 'center'
},
'.cm-autocomplete-item > div.icon': {
marginRight: '10px'
},
'.cm-autocomplete-item .cm-completionIcon-keyword': {
paddingRight: '24px'
Expand Down Expand Up @@ -319,8 +323,9 @@ const customAutoCompletion = (config: AutoCompletionConfig) => {
}

if (src) {
const element = document.createElement('img')
element.src = src
const element = document.createElement('div')
element.className = 'icon'
element.innerHTML = src
return element
} else {
return null
Expand All @@ -347,6 +352,6 @@ const autoCompleteTab = (config: AutoCompletionConfig) => {
])
}

export function autoCompletion(config: AutoCompletionConfig) {
export function autoCompletion(config: AutoCompletionConfig = {}) {
return [baseTheme, customAutoCompletion(config), autoCompleteTab(config)]
}
18 changes: 9 additions & 9 deletions packages/extensions/cur-sql-gutter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ export interface CurSqlGutterConfig {
backgroundColor?: string
width?: number
className?: string
shouldDisplay?: (view: EditorView) => boolean
whenHide?: (view: EditorView) => boolean
}

function getMarkers(
view: EditorView,
curSqlMarker: GutterMarker,
config?: CurSqlGutterConfig
config: CurSqlGutterConfig
) {
let markers = RangeSet.empty

// when something happens, hide the gutter
if (config?.shouldDisplay && !config.shouldDisplay(view)) {
if (config.whenHide && config.whenHide(view)) {
return markers
}

Expand Down Expand Up @@ -54,10 +54,10 @@ function getMarkers(
/**
* gutter style
*/
const baseTheme = (config?: CurSqlGutterConfig) => {
const baseTheme = (config: CurSqlGutterConfig) => {
return EditorView.baseTheme({
'.cm-sql-gutter .cm-gutterElement': {
width: `${config?.width ?? 2}px`
width: `${config.width ?? 2}px`
},
'.cm-lineNumbers .cm-gutterElement': {
paddingLeft: '8px',
Expand All @@ -66,19 +66,19 @@ const baseTheme = (config?: CurSqlGutterConfig) => {
})
}

const sqlGutter = (curSqlMarker: GutterMarker, config?: CurSqlGutterConfig) => {
const sqlGutter = (curSqlMarker: GutterMarker, config: CurSqlGutterConfig) => {
return gutter({
class: `cm-sql-gutter ${config?.className || ''}`,
class: `cm-sql-gutter ${config.className || ''}`,
initialSpacer: () => curSqlMarker,
markers: (view: EditorView) => getMarkers(view, curSqlMarker, config)
})
}

export const curSqlGutter = (config?: CurSqlGutterConfig) => {
export const curSqlGutter = (config: CurSqlGutterConfig = {}) => {
const curSqlMarker = new (class extends GutterMarker {
toDOM() {
const el = document.createElement('div')
el.style.background = config?.backgroundColor || '#0CA6F2'
el.style.background = config.backgroundColor || '#0CA6F2'
el.style.height = '100%'
return el
}
Expand Down
44 changes: 0 additions & 44 deletions packages/extensions/grammar-linter/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/extensions/grammar-linter/rollup.config.js

This file was deleted.

148 changes: 0 additions & 148 deletions packages/extensions/grammar-linter/src/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/extensions/grammar-linter/tsconfig.json

This file was deleted.

Loading