Skip to content

Commit ce68f90

Browse files
committed
Autocomplete part 1: Plugins API
1 parent 734bcf9 commit ce68f90

File tree

7 files changed

+95
-13
lines changed

7 files changed

+95
-13
lines changed

.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_ios","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_ios-2.0.7\\\\","dependencies":[]},{"name":"permission_handler","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-8.3.0\\\\","dependencies":[]},{"name":"shared_preferences_ios","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.0.8\\\\","dependencies":[]},{"name":"url_launcher","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-6.0.15\\\\","dependencies":[]}],"android":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_android","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_android-2.0.9\\\\","dependencies":[]},{"name":"permission_handler","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-8.3.0\\\\","dependencies":[]},{"name":"shared_preferences_android","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.9\\\\","dependencies":[]},{"name":"url_launcher","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-6.0.15\\\\","dependencies":[]}],"macos":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_macos","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.3\\\\","dependencies":[]},{"name":"shared_preferences_macos","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.2\\\\","dependencies":[]},{"name":"url_launcher_macos","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_macos-2.0.2\\\\","dependencies":[]}],"linux":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_linux","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.2\\\\","dependencies":[]},{"name":"shared_preferences_linux","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.0.3\\\\","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_linux-2.0.2\\\\","dependencies":[]}],"windows":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_windows","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.4\\\\","dependencies":[]},{"name":"shared_preferences_windows","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.0.3\\\\","dependencies":["path_provider_windows"]},{"name":"url_launcher_windows","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_windows-2.0.2\\\\","dependencies":[]}],"web":[{"name":"shared_preferences_web","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.2\\\\","dependencies":[]},{"name":"url_launcher_web","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_jscore","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-12-17 19:34:54.759457","version":"2.8.0"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_ios","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_ios-2.0.7\\\\","dependencies":[]},{"name":"permission_handler","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-8.3.0\\\\","dependencies":[]},{"name":"shared_preferences_ios","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.0.8\\\\","dependencies":[]},{"name":"url_launcher","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-6.0.15\\\\","dependencies":[]}],"android":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_android","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_android-2.0.9\\\\","dependencies":[]},{"name":"permission_handler","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-8.3.0\\\\","dependencies":[]},{"name":"shared_preferences_android","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.9\\\\","dependencies":[]},{"name":"url_launcher","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-6.0.15\\\\","dependencies":[]}],"macos":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_macos","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.3\\\\","dependencies":[]},{"name":"shared_preferences_macos","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.2\\\\","dependencies":[]},{"name":"url_launcher_macos","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_macos-2.0.2\\\\","dependencies":[]}],"linux":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_linux","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.2\\\\","dependencies":[]},{"name":"shared_preferences_linux","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.0.3\\\\","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_linux-2.0.2\\\\","dependencies":[]}],"windows":[{"name":"flutter_jscore","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_jscore-1.0.0\\\\","dependencies":[]},{"name":"path_provider_windows","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.4\\\\","dependencies":[]},{"name":"shared_preferences_windows","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.0.3\\\\","dependencies":["path_provider_windows"]},{"name":"url_launcher_windows","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_windows-2.0.2\\\\","dependencies":[]}],"web":[{"name":"shared_preferences_web","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.2\\\\","dependencies":[]},{"name":"url_launcher_web","path":"D:\\\\Programming\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_jscore","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-12-19 11:12:07.031666","version":"2.8.0"}

lib/contrib/code_text_field-1.0.2m/lib/src/code_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class EditorParams {
1414
}
1515

1616
class CodeController extends TextEditingController {
17-
/// A highligh language to parse the text with
17+
/// A highlight language to parse the text with
1818
final Mode? language;
1919

2020
/// The theme to apply to the [language] parsing result
@@ -47,7 +47,7 @@ class CodeController extends TextEditingController {
4747
final String languageId = _genId();
4848
final styleList = <TextStyle>[];
4949
final modifierMap = <String, CodeModifier>{};
50-
final autoCompleteKeystroke = <String>[".",":"];
50+
final autoCompleteKeystroke = <String>[".",":"]; //TODO: make this controllable by plugins
5151
RegExp? styleRegExp;
5252

5353
CodeController({

lib/editor.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import 'dart:io';
44
import 'package:corecoder_develop/util/custom_code_box.dart'
55
show InnerField, InnerFieldState;
66
import 'package:corecoder_develop/editor_drawer.dart';
7+
import 'package:corecoder_develop/util/modules_manager.dart';
78
import 'package:corecoder_develop/util/theme_manager.dart';
9+
import 'package:flutter/cupertino.dart';
810
import 'package:tabbed_view/tabbed_view.dart';
911
import 'package:flutter/material.dart';
1012
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
@@ -183,6 +185,10 @@ class _EditorPageState extends State<EditorPage> {
183185
autoSaveTimer.reset();
184186
},
185187
onAutoComplete: (String lastToken) {
188+
autoComplete = [];
189+
for(var module in ModulesManager.modules){
190+
autoComplete.addAll(module.onAutoComplete(language, lastToken));
191+
}
186192
setState(() {
187193
autoCompleteShown = true;
188194
});
@@ -231,6 +237,11 @@ class _EditorPageState extends State<EditorPage> {
231237
var item = autoComplete[index].split("|");
232238
var type = item[0];
233239
var name = item[1];
240+
var desc = "";
241+
if(item.length > 2)
242+
{
243+
desc = item[2];
244+
}
234245
var color = Colors.black12;
235246
switch(type){
236247
case "var":
@@ -256,7 +267,9 @@ class _EditorPageState extends State<EditorPage> {
256267
),
257268
Text(
258269
name,
259-
)
270+
),
271+
const Spacer(),
272+
Flexible(child:Text(desc,overflow: TextOverflow.ellipsis,))
260273
],
261274
),
262275
onTap: () {

lib/modules/module_jsplugins.dart

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import 'package:flutter_jscore/flutter_jscore.dart' as jscore
1919
JSStaticFunction,
2020
JSValue,
2121
JSPropertyNameArray,
22+
JSStaticValueArray,
23+
JSTypedArrayType,
2224
JSValuePointer;
2325

2426
class JsModule extends Module {
@@ -30,6 +32,7 @@ class JsModule extends Module {
3032

3133
Pointer get _ctxPtr => context.pointer;
3234
late Pointer _globalObjPtr;
35+
List<String> Function(String lang, String lastToken)? onAutocomplete;
3336

3437
/// Expose the CoreCoder class to js
3538
void initializeCC3JS() {
@@ -185,20 +188,80 @@ class JsModule extends Module {
185188
1,
186189
context.exception.pointer);
187190

188-
if(context.exception.getValue(context).isNull == false){
191+
if (context.exception.getValue(context).isNull == false) {
189192
var errorObj = context.exception.getValue(context).toObject();
190193
var name = errorObj.getProperty("name").string;
191194
var message = errorObj.getProperty("message").string;
192195
var lineNumber = errorObj.getProperty("line").string;
193196
debugPrint("[JSError](line $lineNumber) $name : $message");
194197
}
195198
context.evaluate(mainScript);
196-
jscore.JSValue onInitializedValue = globalObj.getProperty("onInitialized");
197-
jscore.JSObject onInitializedObj = onInitializedValue.toObject();
198-
jscore.JSValuePointer? err;
199-
onInitializedObj.callAsFunction(globalObj, jscore.JSValuePointer.array([]),exception: err);
200-
if(err != null && err.getValue(context).isNull == false){
201-
debugPrint("[JSError] ${err.getValue(context).toString()}");
199+
200+
/// ************************
201+
/// Overridable functions
202+
/// ************************
203+
204+
if (globalObj.hasProperty("onInitialized")) {
205+
jscore.JSValue onInitializedValue =
206+
globalObj.getProperty("onInitialized");
207+
jscore.JSObject onInitializedObj = onInitializedValue.toObject();
208+
jscore.JSValuePointer? err;
209+
onInitializedObj.callAsFunction(
210+
globalObj, jscore.JSValuePointer.array([]),
211+
exception: err);
212+
if (err != null && err.getValue(context).isNull == false) {
213+
debugPrint("[JSError] ${err.getValue(context).toString()}");
214+
}
215+
}
216+
217+
if (globalObj.hasProperty("onGetAutocomplete")) {
218+
jscore.JSValue onInitializedValue =
219+
globalObj.getProperty("onGetAutocomplete");
220+
jscore.JSObject onInitializedObj = onInitializedValue.toObject();
221+
onAutocomplete = (String lang, String lastToken) {
222+
var result = <String>[];
223+
jscore.JSValuePointer? err;
224+
var jsResult = onInitializedObj.callAsFunction(
225+
globalObj, jscore.JSValuePointer.array([
226+
jscore.JSValue.makeString(context, "string"),
227+
jscore.JSValue.makeString(context, "love"),
228+
]),
229+
exception: err);
230+
if (err != null && err.getValue(context).isNull == false) {
231+
debugPrint("[JSError] ${err.getValue(context).toString()}");
232+
}
233+
if(jsResult.isObject){
234+
var arr = jsResult.toObject();
235+
var props = arr.copyPropertyNames();
236+
for(var i = 0; i < props.count; i++){
237+
var name = props.propertyNameArrayGetNameAtIndex(i);
238+
if(lastToken != "" && name == lastToken){
239+
var inner = arr.getProperty(name).toObject();
240+
var props2 = inner.copyPropertyNames();
241+
for(var k = 0; k < props2.count; k++) {
242+
result.add(props2.propertyNameArrayGetNameAtIndex(k));
243+
}
244+
}
245+
if(lastToken == ""){
246+
result.add(name);
247+
}
248+
}
249+
}else{
250+
debugPrint("It's not an object");
251+
}
252+
return result;
253+
};
254+
}
255+
}
256+
257+
@override
258+
List<String> onAutoComplete(String language, String lastToken) {
259+
if(onAutocomplete != null) {
260+
List<String>? list = onAutocomplete?.call(language, lastToken);
261+
if(list != null){
262+
return list;
263+
}
202264
}
265+
return [];
203266
}
204267
}

lib/modules/module_minecraft.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,11 @@ class MinecraftModule extends Module {
303303
templates.add(bpTemplate);
304304
templates.add(rpTemplate);
305305
}
306+
307+
@override
308+
List<String> onAutoComplete(String language, String lastToken) {
309+
// TODO: implement onAutoComplete
310+
return [];
311+
}
312+
306313
}

lib/util/custom_code_box.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ class InnerField extends StatelessWidget {
154154
onCursorPosChanged: setCursorOffset,
155155
controller: codeController,
156156
textStyle: const TextStyle(fontFamily: 'SourceCode'),
157-
158157
);
159158
}
160159

lib/util/modules_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ abstract class Module {
9393
this.identifier);
9494

9595
void onInitialized(ModulesManager modulesManager, BuildContext buildContext);
96-
96+
List<String> onAutoComplete(String language, String lastToken);
9797
void addTemplate(Template template) {
9898
templates.add(template);
9999
}

0 commit comments

Comments
 (0)