@difizen/libro-cofine-editor 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/es/editor-contribution.d.ts +10 -0
- package/es/editor-contribution.d.ts.map +1 -0
- package/es/editor-contribution.js +31 -0
- package/es/index.d.ts +7 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +6 -0
- package/es/index.less +32 -0
- package/es/language/lsp/completion-provider.d.ts +13 -0
- package/es/language/lsp/completion-provider.d.ts.map +1 -0
- package/es/language/lsp/completion-provider.js +290 -0
- package/es/language/lsp/diagnostic-provider.d.ts +22 -0
- package/es/language/lsp/diagnostic-provider.d.ts.map +1 -0
- package/es/language/lsp/diagnostic-provider.js +161 -0
- package/es/language/lsp/format-provider.d.ts +9 -0
- package/es/language/lsp/format-provider.d.ts.map +1 -0
- package/es/language/lsp/format-provider.js +139 -0
- package/es/language/lsp/hover-provider.d.ts +8 -0
- package/es/language/lsp/hover-provider.d.ts.map +1 -0
- package/es/language/lsp/hover-provider.js +136 -0
- package/es/language/lsp/language-feature-provider.d.ts +17 -0
- package/es/language/lsp/language-feature-provider.d.ts.map +1 -0
- package/es/language/lsp/language-feature-provider.js +89 -0
- package/es/language/lsp/lsp-contribution.d.ts +25 -0
- package/es/language/lsp/lsp-contribution.d.ts.map +1 -0
- package/es/language/lsp/lsp-contribution.js +213 -0
- package/es/language/lsp/module.d.ts +2 -0
- package/es/language/lsp/module.d.ts.map +1 -0
- package/es/language/lsp/module.js +3 -0
- package/es/language/lsp/semantic-highlight-provider.d.ts +9 -0
- package/es/language/lsp/semantic-highlight-provider.d.ts.map +1 -0
- package/es/language/lsp/semantic-highlight-provider.js +41 -0
- package/es/language/lsp/signature-help-provider.d.ts +8 -0
- package/es/language/lsp/signature-help-provider.d.ts.map +1 -0
- package/es/language/lsp/signature-help-provider.js +108 -0
- package/es/language/lsp/type-concerters.d.ts +7 -0
- package/es/language/lsp/type-concerters.d.ts.map +1 -0
- package/es/language/lsp/type-concerters.js +37 -0
- package/es/language/python/data/MagicPython.tmLanguage.json +4213 -0
- package/es/language/python/data/MagicRegExp.tmLanguage.json +497 -0
- package/es/language/python/data/configurations/python.json +135 -0
- package/es/language/python/data/snippets/python.snippets.json +223 -0
- package/es/language/python/module.d.ts +2 -0
- package/es/language/python/module.d.ts.map +1 -0
- package/es/language/python/module.js +3 -0
- package/es/language/python/python-builtin.d.ts +86 -0
- package/es/language/python/python-builtin.d.ts.map +1 -0
- package/es/language/python/python-builtin.js +569 -0
- package/es/language/python/python-language-feature.d.ts +26 -0
- package/es/language/python/python-language-feature.d.ts.map +1 -0
- package/es/language/python/python-language-feature.js +174 -0
- package/es/language-specs.d.ts +33 -0
- package/es/language-specs.d.ts.map +1 -0
- package/es/language-specs.js +115 -0
- package/es/libro-e2-editor.d.ts +277 -0
- package/es/libro-e2-editor.d.ts.map +1 -0
- package/es/libro-e2-editor.js +720 -0
- package/es/libro-e2-preload.d.ts +5 -0
- package/es/libro-e2-preload.d.ts.map +1 -0
- package/es/libro-e2-preload.js +57 -0
- package/es/libro-sql-api.d.ts +8 -0
- package/es/libro-sql-api.d.ts.map +1 -0
- package/es/libro-sql-api.js +26 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +44 -0
- package/es/placeholder.d.ts +31 -0
- package/es/placeholder.d.ts.map +1 -0
- package/es/placeholder.js +101 -0
- package/es/theme/data/jupyter_dark.json +406 -0
- package/es/theme/data/jupyter_hc_dark.json +385 -0
- package/es/theme/data/jupyter_hc_light.json +386 -0
- package/es/theme/data/jupyter_light.json +386 -0
- package/es/theme/data/libro_dark.json +186 -0
- package/es/theme/data/libro_light.json +170 -0
- package/es/theme/libro-python-theme-contribution.d.ts +6 -0
- package/es/theme/libro-python-theme-contribution.d.ts.map +1 -0
- package/es/theme/libro-python-theme-contribution.js +49 -0
- package/es/theme/module.d.ts +2 -0
- package/es/theme/module.d.ts.map +1 -0
- package/es/theme/module.js +3 -0
- package/es/types.d.ts +10 -0
- package/es/types.d.ts.map +1 -0
- package/es/types.js +3 -0
- package/package.json +67 -0
- package/src/editor-contribution.ts +30 -0
- package/src/index.less +32 -0
- package/src/index.spec.ts +8 -0
- package/src/index.ts +6 -0
- package/src/language/lsp/completion-provider.ts +214 -0
- package/src/language/lsp/diagnostic-provider.ts +148 -0
- package/src/language/lsp/format-provider.ts +87 -0
- package/src/language/lsp/hover-provider.ts +98 -0
- package/src/language/lsp/language-feature-provider.ts +69 -0
- package/src/language/lsp/lsp-contribution.ts +159 -0
- package/src/language/lsp/module.ts +5 -0
- package/src/language/lsp/semantic-highlight-provider.ts +26 -0
- package/src/language/lsp/signature-help-provider.ts +65 -0
- package/src/language/lsp/type-concerters.ts +72 -0
- package/src/language/python/data/MagicPython.tmLanguage.json +4213 -0
- package/src/language/python/data/MagicRegExp.tmLanguage.json +497 -0
- package/src/language/python/data/configurations/python.json +135 -0
- package/src/language/python/data/snippets/python.snippets.json +223 -0
- package/src/language/python/module.ts +5 -0
- package/src/language/python/python-builtin.ts +891 -0
- package/src/language/python/python-language-feature.ts +163 -0
- package/src/language-specs.ts +99 -0
- package/src/libro-e2-editor.ts +922 -0
- package/src/libro-e2-preload.ts +23 -0
- package/src/libro-sql-api.ts +20 -0
- package/src/module.ts +44 -0
- package/src/placeholder.ts +100 -0
- package/src/theme/data/jupyter_dark.json +406 -0
- package/src/theme/data/jupyter_hc_dark.json +385 -0
- package/src/theme/data/jupyter_hc_light.json +386 -0
- package/src/theme/data/jupyter_light.json +386 -0
- package/src/theme/data/libro_dark.json +186 -0
- package/src/theme/data/libro_light.json +170 -0
- package/src/theme/libro-python-theme-contribution.ts +36 -0
- package/src/theme/module.ts +5 -0
- package/src/types.ts +11 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { SnippetSuggestRegistry } from '@difizen/libro-cofine-editor-core';
|
|
2
|
+
import {
|
|
3
|
+
InitializeContribution,
|
|
4
|
+
LanguageOptionsRegistry,
|
|
5
|
+
SnippetSuggestContribution,
|
|
6
|
+
} from '@difizen/libro-cofine-editor-core';
|
|
7
|
+
import type {
|
|
8
|
+
GrammarDefinition,
|
|
9
|
+
TextmateRegistry,
|
|
10
|
+
} from '@difizen/libro-cofine-textmate';
|
|
11
|
+
import { LanguageGrammarDefinitionContribution } from '@difizen/libro-cofine-textmate';
|
|
12
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
13
|
+
import { languages } from '@difizen/monaco-editor-core';
|
|
14
|
+
import * as monaco from '@difizen/monaco-editor-core';
|
|
15
|
+
|
|
16
|
+
import pythonGrammar from './data/MagicPython.tmLanguage.json';
|
|
17
|
+
import regExpGrammar from './data/MagicRegExp.tmLanguage.json';
|
|
18
|
+
import snippetsJson from './data/snippets/python.snippets.json';
|
|
19
|
+
|
|
20
|
+
export interface PythonLanguageOption {
|
|
21
|
+
lspHost: {
|
|
22
|
+
host: string;
|
|
23
|
+
path: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isPythonLanguageOption(data: object): data is PythonLanguageOption {
|
|
28
|
+
return data && typeof data === 'object' && 'lspHost' in data;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let langRegisted = false;
|
|
32
|
+
let grammerRegisted = false;
|
|
33
|
+
|
|
34
|
+
@singleton({
|
|
35
|
+
contrib: [
|
|
36
|
+
LanguageGrammarDefinitionContribution,
|
|
37
|
+
SnippetSuggestContribution,
|
|
38
|
+
InitializeContribution,
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
export class PythonContribution
|
|
42
|
+
implements
|
|
43
|
+
LanguageGrammarDefinitionContribution,
|
|
44
|
+
SnippetSuggestContribution,
|
|
45
|
+
InitializeContribution
|
|
46
|
+
{
|
|
47
|
+
protected readonly optionsResgistry: LanguageOptionsRegistry;
|
|
48
|
+
|
|
49
|
+
readonly id = 'python';
|
|
50
|
+
readonly config: languages.LanguageConfiguration = {
|
|
51
|
+
comments: {
|
|
52
|
+
lineComment: '#',
|
|
53
|
+
},
|
|
54
|
+
brackets: [
|
|
55
|
+
['{', '}'],
|
|
56
|
+
['[', ']'],
|
|
57
|
+
['(', ')'],
|
|
58
|
+
],
|
|
59
|
+
autoClosingPairs: [
|
|
60
|
+
{ open: '[', close: ']' },
|
|
61
|
+
{ open: '{', close: '}' },
|
|
62
|
+
{ open: '(', close: ')' },
|
|
63
|
+
{ open: "'", close: "'", notIn: ['string', 'comment'] },
|
|
64
|
+
{ open: '"', close: '"', notIn: ['string'] },
|
|
65
|
+
],
|
|
66
|
+
surroundingPairs: [
|
|
67
|
+
{ open: '{', close: '}' },
|
|
68
|
+
{ open: '[', close: ']' },
|
|
69
|
+
{ open: '(', close: ')' },
|
|
70
|
+
{ open: '"', close: '"' },
|
|
71
|
+
{ open: "'", close: "'" },
|
|
72
|
+
],
|
|
73
|
+
folding: {
|
|
74
|
+
markers: {
|
|
75
|
+
start: new RegExp('^\\s*#pragma\\s+region\\b'),
|
|
76
|
+
end: new RegExp('^\\s*#pragma\\s+endregion\\b'),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
onEnterRules: [
|
|
80
|
+
{
|
|
81
|
+
beforeText:
|
|
82
|
+
/^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\s*$/,
|
|
83
|
+
action: { indentAction: languages.IndentAction.Indent },
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
constructor(
|
|
89
|
+
@inject(LanguageOptionsRegistry) optionsResgistry: LanguageOptionsRegistry,
|
|
90
|
+
) {
|
|
91
|
+
this.optionsResgistry = optionsResgistry;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onInitialize() {
|
|
95
|
+
monaco.languages.register({
|
|
96
|
+
id: this.id,
|
|
97
|
+
extensions: [
|
|
98
|
+
'.py',
|
|
99
|
+
'.rpy',
|
|
100
|
+
'.pyw',
|
|
101
|
+
'.cpy',
|
|
102
|
+
'.gyp',
|
|
103
|
+
'.gypi',
|
|
104
|
+
'.snakefile',
|
|
105
|
+
'.smk',
|
|
106
|
+
],
|
|
107
|
+
aliases: ['Python', 'py'],
|
|
108
|
+
firstLine: '^#!\\s*/.*\\bpython[0-9.-]*\\b',
|
|
109
|
+
});
|
|
110
|
+
monaco.languages.onLanguage(this.id, () => {
|
|
111
|
+
this.registerLanguageFeature();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
protected registerLanguageFeature() {
|
|
116
|
+
if (langRegisted) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
langRegisted = true;
|
|
120
|
+
monaco.languages.setLanguageConfiguration(this.id, this.config);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
registerSnippetSuggest(registry: SnippetSuggestRegistry) {
|
|
124
|
+
registry.fromJSON(snippetsJson, {
|
|
125
|
+
language: [this.id],
|
|
126
|
+
source: 'Python Language',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
registerTextmateLanguage(registry: TextmateRegistry): void {
|
|
131
|
+
if (grammerRegisted) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
grammerRegisted = true;
|
|
135
|
+
|
|
136
|
+
registry.registerTextmateGrammarScope('source.python', {
|
|
137
|
+
async getGrammarDefinition(): Promise<GrammarDefinition> {
|
|
138
|
+
return {
|
|
139
|
+
format: 'json',
|
|
140
|
+
content: pythonGrammar,
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
registry.registerTextmateGrammarScope('source.regexp.python', {
|
|
146
|
+
async getGrammarDefinition(): Promise<GrammarDefinition> {
|
|
147
|
+
return {
|
|
148
|
+
format: 'json',
|
|
149
|
+
content: regExpGrammar,
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
registry.mapLanguageIdToTextmateGrammar(this.id, 'source.python');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected isDisposed = false;
|
|
157
|
+
get disposed() {
|
|
158
|
+
return this.isDisposed;
|
|
159
|
+
}
|
|
160
|
+
dispose() {
|
|
161
|
+
this.isDisposed = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { ApplicationContribution } from '@difizen/mana-app';
|
|
3
|
+
import { contrib, inject, singleton, Syringe } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import type { LibroE2Editor, LibroE2EditorConfig } from './libro-e2-editor.js';
|
|
6
|
+
import { LibroSQLRequestAPI } from './libro-sql-api.js';
|
|
7
|
+
|
|
8
|
+
export const LanguageSpecContribution = Syringe.defineToken('LanguageSpecContribution');
|
|
9
|
+
export interface LanguageSpecContribution {
|
|
10
|
+
registerLanguageSpec: (register: LanguageSpecRegistry) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface LanguageSpec {
|
|
13
|
+
name: string;
|
|
14
|
+
language: string;
|
|
15
|
+
mime: string;
|
|
16
|
+
ext: string[];
|
|
17
|
+
loadModule?: (container: Syringe.Container) => Promise<void>;
|
|
18
|
+
beforeEditorInit?: () => Promise<void>;
|
|
19
|
+
editorConfig?: Partial<LibroE2EditorConfig>;
|
|
20
|
+
afterEditorInit?: (editor: LibroE2Editor) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@singleton({ contrib: [ApplicationContribution] })
|
|
24
|
+
export class LanguageSpecRegistry implements ApplicationContribution {
|
|
25
|
+
get languageSpecs(): LanguageSpec[] {
|
|
26
|
+
return this.languageSpecsData;
|
|
27
|
+
}
|
|
28
|
+
protected languageSpecsData: LanguageSpec[] = [];
|
|
29
|
+
|
|
30
|
+
protected readonly languageSpecProvider: Contribution.Provider<LanguageSpecContribution>;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
@contrib(LanguageSpecContribution)
|
|
34
|
+
languageSpecProvider: Contribution.Provider<LanguageSpecContribution>,
|
|
35
|
+
) {
|
|
36
|
+
this.languageSpecProvider = languageSpecProvider;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
initialize() {
|
|
40
|
+
this.languageSpecProvider.getContributions().forEach((item) => {
|
|
41
|
+
item.registerLanguageSpec(this);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
registerLanguageSpec(spec: LanguageSpec) {
|
|
46
|
+
const index = this.languageSpecsData.findIndex(
|
|
47
|
+
(item) => item.language === spec.language,
|
|
48
|
+
);
|
|
49
|
+
if (index >= 0) {
|
|
50
|
+
this.languageSpecsData.splice(index, 1, spec);
|
|
51
|
+
} else {
|
|
52
|
+
this.languageSpecsData.push(spec);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
hasLanguage(spec: LanguageSpec) {
|
|
57
|
+
return (
|
|
58
|
+
this.languageSpecsData.findIndex((item) => item.language === spec.language) > 0
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@singleton({ contrib: [LanguageSpecContribution] })
|
|
64
|
+
export class LibroLanguageSpecs implements LanguageSpecContribution {
|
|
65
|
+
@inject(LibroSQLRequestAPI)
|
|
66
|
+
protected readonly dataphinAPI: LibroSQLRequestAPI;
|
|
67
|
+
|
|
68
|
+
registerLanguageSpec = (register: LanguageSpecRegistry) => {
|
|
69
|
+
register.registerLanguageSpec({
|
|
70
|
+
name: 'Python',
|
|
71
|
+
language: 'python',
|
|
72
|
+
ext: ['.py'],
|
|
73
|
+
mime: 'text/x-python',
|
|
74
|
+
editorConfig: {},
|
|
75
|
+
});
|
|
76
|
+
register.registerLanguageSpec({
|
|
77
|
+
name: 'SQL',
|
|
78
|
+
mime: 'application/vnd.libro.sql+json',
|
|
79
|
+
language: 'sql-odps',
|
|
80
|
+
ext: ['.sql'],
|
|
81
|
+
editorConfig: {},
|
|
82
|
+
beforeEditorInit: async () => {
|
|
83
|
+
//
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
register.registerLanguageSpec({
|
|
87
|
+
name: 'Markdown',
|
|
88
|
+
language: 'markdown',
|
|
89
|
+
mime: 'text/x-markdown',
|
|
90
|
+
ext: ['md', 'markdown', 'mkd'],
|
|
91
|
+
});
|
|
92
|
+
register.registerLanguageSpec({
|
|
93
|
+
name: 'Prompt',
|
|
94
|
+
language: 'markdown',
|
|
95
|
+
mime: 'application/vnd.libro.prompt+json',
|
|
96
|
+
ext: ['md', 'markdown', 'mkd'],
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|