Improved PL/PGSQL code folding and support nested blocks. #6118
parent
3286b4e32f
commit
4a4d4569ae
|
|
@ -39,6 +39,11 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Update python version
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Setup the EDB APT repo on Linux
|
||||
if: ${{ matrix.os == 'ubuntu-22.04' }}
|
||||
run: |
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Update python version
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Setup the PGDG APT repo on Linux
|
||||
if: ${{ matrix.os == 'ubuntu-22.04' }}
|
||||
run: |
|
||||
|
|
|
|||
|
|
@ -28,4 +28,6 @@ Housekeeping
|
|||
Bug fixes
|
||||
*********
|
||||
|
||||
| `Issue #8032 <https://github.com/pgadmin-org/pgadmin4/issues/8032>`_ - Fixed an issue where the Schema Diff Tool incorrectly reported differences due to variations in the order of the privileges.
|
||||
| `Issue #6118 <https://github.com/pgadmin-org/pgadmin4/issues/6118>`_ - Improved PL/pgSQL code folding and support nested blocks.
|
||||
| `Issue #8032 <https://github.com/pgadmin-org/pgadmin4/issues/8032>`_ - Fixed an issue where the Schema Diff Tool incorrectly reported differences due to variations in the order of the privileges.
|
||||
| `Issue #8691 <https://github.com/pgadmin-org/pgadmin4/issues/8691>`_ - Fixed an issue in the query tool where using multiple cursors to copy text resulted in only the first line being copied.
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@
|
|||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"@babel/preset-react": "^7.12.13",
|
||||
"@codemirror/lang-json": "^6.0.1",
|
||||
"@codemirror/lang-sql": "^6.8.0",
|
||||
"@codemirror/lang-sql": "^6.9.0",
|
||||
"@date-io/core": "^3.0.0",
|
||||
"@date-io/date-fns": "3.x",
|
||||
"@emotion/sheet": "^1.0.1",
|
||||
|
|
|
|||
|
|
@ -54,9 +54,10 @@ import currentQueryHighlighterExtn from '../extensions/currentQueryHighlighter';
|
|||
import { autoCompleteCompartment, eolCompartment, indentNewLine, eol } from '../extensions/extraStates';
|
||||
import { OS_EOL } from '../../../../../tools/sqleditor/static/js/components/QueryToolConstants';
|
||||
import { useTheme } from '@mui/material';
|
||||
import plpgsqlFoldService from '../extensions/plpgsqlFoldService';
|
||||
|
||||
const arrowRightHtml = ReactDOMServer.renderToString(<KeyboardArrowRightRoundedIcon style={{width: '16px'}} />);
|
||||
const arrowDownHtml = ReactDOMServer.renderToString(<ExpandMoreRoundedIcon style={{width: '16px'}} />);
|
||||
const arrowRightHtml = ReactDOMServer.renderToString(<KeyboardArrowRightRoundedIcon style={{width: '16px', fill: 'currentcolor'}} />);
|
||||
const arrowDownHtml = ReactDOMServer.renderToString(<ExpandMoreRoundedIcon style={{width: '16px', fill: 'currentcolor'}} />);
|
||||
|
||||
function handleDrop(e, editor) {
|
||||
let dropDetails = null;
|
||||
|
|
@ -158,7 +159,9 @@ const defaultExtensions = [
|
|||
autoCompleteCompartment.of([]),
|
||||
EditorView.clipboardOutputFilter.of((text, state)=>{
|
||||
return CustomEditorView.getSelectionFromState(state);
|
||||
})
|
||||
}),
|
||||
// Custom folding service for PL/pgSQL
|
||||
plpgsqlFoldService,
|
||||
];
|
||||
|
||||
export default function Editor({
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { SQLDialect, PostgreSQL } from '@codemirror/lang-sql';
|
||||
import { foldNodeProp } from '@codemirror/language';
|
||||
|
||||
const extraKeywords = 'unsafe';
|
||||
const keywords = PostgreSQL.spec.keywords.replace(/\b\w\b/, '') + ' ' + extraKeywords;
|
||||
|
|
@ -10,5 +11,14 @@ const PgSQL = SQLDialect.define({
|
|||
specialVar: '',
|
||||
keywords: keywords,
|
||||
types: PostgreSQL.spec.types,
|
||||
}).configureLanguage({
|
||||
// Disable default folding behavior as it conflicts with custom folding
|
||||
props: [
|
||||
foldNodeProp.add({
|
||||
Statement() { return null; },
|
||||
BlockComment() { return null; }
|
||||
}),
|
||||
]
|
||||
});
|
||||
|
||||
export default PgSQL;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
import { foldService } from '@codemirror/language';
|
||||
|
||||
function findRange(pair, state, startLine) {
|
||||
let depth = 1;
|
||||
const from = startLine.to;
|
||||
|
||||
for (let i = startLine.number + 1; i <= state.doc.lines; i++) {
|
||||
const line = state.doc.line(i);
|
||||
const text = line.text.trim();
|
||||
|
||||
if (pair.start.test(text)) {
|
||||
depth++;
|
||||
} else if (pair.end.test(text)) {
|
||||
depth--;
|
||||
if (depth === 0) {
|
||||
// Only fold if there is at least one line between the start and end.
|
||||
if (i <= startLine.number + 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// leaving the closing keyword line visible after folding.
|
||||
const to = state.doc.line(i - 1).to;
|
||||
return { from, to };
|
||||
}
|
||||
}
|
||||
}
|
||||
// No valid closing block found
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const plpgsqlFoldService = foldService.of((state, startPos) => {
|
||||
const startLine = state.doc.lineAt(startPos);
|
||||
const startText = startLine.text.trim();
|
||||
|
||||
const foldPairs = [
|
||||
// Added 'i' flag for case-insensitivity
|
||||
{ start: /^BEGIN\b/i, end: /^END\b\s*;$/i },
|
||||
{ start: /^IF\b/i, end: /^END IF\b\s*;$/i },
|
||||
{ start: /^FOR\b/i, end: /^END LOOP\b\s*;$/i },
|
||||
{ start: /^CASE\b/i, end: /^END CASE\b\s*;$/i }
|
||||
];
|
||||
|
||||
for (let pair of foldPairs) {
|
||||
if (pair.start.test(startText)) {
|
||||
return findRange(pair, state, startLine);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
export default plpgsqlFoldService;
|
||||
|
|
@ -1497,9 +1497,9 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@codemirror/lang-sql@npm:^6.8.0":
|
||||
version: 6.8.0
|
||||
resolution: "@codemirror/lang-sql@npm:6.8.0"
|
||||
"@codemirror/lang-sql@npm:^6.9.0":
|
||||
version: 6.9.0
|
||||
resolution: "@codemirror/lang-sql@npm:6.9.0"
|
||||
dependencies:
|
||||
"@codemirror/autocomplete": ^6.0.0
|
||||
"@codemirror/language": ^6.0.0
|
||||
|
|
@ -1507,7 +1507,7 @@ __metadata:
|
|||
"@lezer/common": ^1.2.0
|
||||
"@lezer/highlight": ^1.0.0
|
||||
"@lezer/lr": ^1.0.0
|
||||
checksum: 1b5a3c8129b09f24039d8c0906fc4cb8d0f706a424a1d56721057bd1e647797c2b1240bb53eed9bf2bac5806a4e0363e555a3963f04c478efa05829890c537f7
|
||||
checksum: aca08c11b519f962e9a59e14dc6f54102deaa7a15a390c2dc50401234d33a1fd0c5d2436e6f1810a0363b6f2649480d28eb16a10a7e3f4221ffa3f130ef0672e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
|
@ -13637,7 +13637,7 @@ __metadata:
|
|||
"@babel/preset-react": ^7.12.13
|
||||
"@babel/preset-typescript": ^7.24.7
|
||||
"@codemirror/lang-json": ^6.0.1
|
||||
"@codemirror/lang-sql": ^6.8.0
|
||||
"@codemirror/lang-sql": ^6.9.0
|
||||
"@date-io/core": ^3.0.0
|
||||
"@date-io/date-fns": 3.x
|
||||
"@emotion/memoize": ^0.9.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue