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

fix: suport multipline of Painless script #115

Merged
merged 5 commits into from
Oct 13, 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: 1 addition & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- name: install dependencies (ubuntu only)
if: matrix.os == 'ubuntu-latest'
run: |
echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install frontend dependencies
Expand Down
29 changes: 15 additions & 14 deletions src/common/monaco/lexerRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ export const search = {
{ include: '@json5' },
],
json5: [
[
/["']?(.*_?script|inline|source)["']?(\s*?)(:)(\s*?)("""|''')/,
[
'variable',
'whitespace',
'delimiter',
'whitespace',
{
token: 'punctuation.start_triple_quote',
nextEmbedded: 'painless',
next: 'search_painless',
},
],
],
// @TODO add painless highlighting & tokenization support
// [
// /["']?(.*_?script|inline|source)["']?(\s*?)(:)(\s*?)("""|''')/,
// [
// 'variable',
// 'whitespace',
// 'delimiter',
// 'whitespace',
// {
// token: 'punctuation.start_triple_quote',
// nextEmbedded: 'painless',
// next: 'search_painless',
// },
// ],
// ],
[
/(:)(\s*?)("""|''')(sql)/,
[
Expand Down
10 changes: 8 additions & 2 deletions src/common/monaco/tokenlizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export const formatQDSL = (
return lines.map(line => JSON5.stringify(line)).join('\n');
};

const replaceTripleQuotes = (value: string) =>
value
.replace(/'''(.*?)'''/gs, (_, match) => JSON.stringify(match))
.replace(/"""(.*?)"""/gs, (_, match) => JSON.stringify(match));

export const transformQDSL = ({ path, qdsl }: Pick<SearchAction, 'path' | 'qdsl'>) => {
try {
const bulkAction = path.includes('_bulk');
Expand All @@ -138,7 +143,7 @@ export const transformQDSL = ({ path, qdsl }: Pick<SearchAction, 'path' | 'qdsl'
return `${bulkQdsl}\n`;
}

return qdsl ? JSON.stringify(JSON5.parse(qdsl), null, 2) : undefined;
return qdsl ? JSON.stringify(JSON5.parse(replaceTripleQuotes(qdsl)), null, 2) : undefined;
} catch (err) {
throw new CustomError(400, (err as Error).message);
}
Expand Down Expand Up @@ -169,7 +174,8 @@ export const transformToCurl = ({
.join('');
}
if (qdsl) {
curlCmd += ` -d '${transformQDSL({ path: url, qdsl })}'`;
const qdslCmd = transformQDSL({ path: url, qdsl })?.replace(/'/g, "'\\''");
curlCmd += ` -d '${qdslCmd}'`;
}

return curlCmd;
Expand Down
Loading