Skip to content

Commit

Permalink
Merge pull request #2 from fugue-project/0.1.6
Browse files Browse the repository at this point in the history
Add more fsql highlight scenarios
  • Loading branch information
Han Wang authored Aug 7, 2022
2 parents 6bc0d37 + 46e8a61 commit 6572da4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fugue-jupyter",
"version": "0.1.5",
"version": "0.1.6",
"description": "Jupyterlab Extension for Fugue",
"keywords": [
"jupyter",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IEditorTracker } from '@jupyterlab/fileeditor';
import {
cellMagicExtractor,
markerExtractor,
fsqlBlockExtractor,
sqlCodeMirrorModesFor,
registerCodeMirrorFor
} from './utils';
Expand Down Expand Up @@ -126,6 +127,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
// and into a virtual document which is then passed to the sql-language-server
// for code completion evaluation
lspExtractorsMgr.register(markerExtractor('fsql'), 'python');
lspExtractorsMgr.register(fsqlBlockExtractor('fsql'), 'python');
lspExtractorsMgr.register(cellMagicExtractor('fsql'), 'python');
console.log('fugue-jupyter LSP extractors registered');
}
Expand Down
24 changes: 23 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import { Mode } from 'codemirror';
import { ICodeMirror } from '@jupyterlab/codemirror';

function cell_magic(language: string) {
return `%%${language}`;
return `%%${language}.*`;
}
function start(language: string) {
return `--start-${language}`;
}
function end(language: string) {
return `--end-${language}`;
}
function fsql_start() {
return `fsql[\\s\\S]*\\([\\s\\S]*\\"\\"\\"`;
}
function fsql_end() {
return `\\"\\"\\"`;
}

const BEGIN = '(?:^|\n)';

Expand All @@ -28,6 +34,12 @@ export function sqlCodeMirrorModesFor(
parseDelimiters: true,
mode: sqlMode
},
{
open: (RegExp(`${fsql_start()}`) as unknown) as string,
close: (RegExp(`${fsql_end()}`) as unknown) as string,
parseDelimiters: false,
mode: sqlMode
},
{
open: (RegExp(`${cell_magic(language)}`) as unknown) as string,
close: '__A MARKER THAT WILL NEVER BE MATCHED__', // Cell magic: capture chars till the end of the cell
Expand Down Expand Up @@ -59,6 +71,16 @@ export function markerExtractor(language: string): RegExpForeignCodeExtractor {
});
}

export function fsqlBlockExtractor(language: string): RegExpForeignCodeExtractor {
return new RegExpForeignCodeExtractor({
language: language,
pattern: `${fsql_start()}.*?\n([^]*?)${fsql_end()}`,
foreign_capture_groups: [1],
is_standalone: true,
file_extension: language
});
}

function set(str: string) {
const obj: any = {},
words = str.split(' ');
Expand Down

0 comments on commit 6572da4

Please sign in to comment.