Skip to content

Commit 52f1c7e

Browse files
author
Paul Verest
committed
make 3 type of content asist optional and enabled by default (change
require restart as checking preferences each time assist is called would add delay)
1 parent 6c84883 commit 52f1c7e

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

org.nodeclipse.ui/src/org/nodeclipse/ui/contentassist/NodeContentAssistant.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
import org.eclipse.jface.preference.IPreferenceStore;
67
import org.eclipse.jface.text.BadLocationException;
78
import org.eclipse.jface.text.IDocument;
89
import org.eclipse.jface.text.ITextViewer;
@@ -16,6 +17,7 @@
1617
import org.json.JSONException;
1718
import org.json.JSONObject;
1819
import org.nodeclipse.ui.Activator;
20+
import org.nodeclipse.ui.preferences.PreferenceConstants;
1921
import org.nodeclipse.ui.util.Constants;
2022
import org.nodeclipse.ui.util.NodeclipseConsole;
2123

@@ -46,7 +48,12 @@ public class NodeContentAssistant implements IContentAssistProcessor {
4648

4749
private boolean indexFilesInitialized = false;
4850

49-
//Model model = new Model();
51+
private IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
52+
boolean useNodejsBaseModuleDefinitions = preferenceStore.getBoolean(PreferenceConstants.USE_NODEJS_BASE_MODULE_DEFINITIONS);//@since 0.12
53+
boolean useOrionIndexFiles = preferenceStore.getBoolean(PreferenceConstants.USE_ORION_INDEX_FILES);//@since 0.12
54+
boolean useCompletionJson = preferenceStore.getBoolean(PreferenceConstants.USE_COMPLETIONS_JSON);//@since 0.12
55+
56+
private Model model = null ; //new Model();
5057

5158
public String getInputString(IDocument doc, int offset) {
5259
StringBuffer buf = new StringBuffer();
@@ -152,8 +159,12 @@ public String getInputString(IDocument doc, int offset) {
152159
private void addCompletionProposalFromModel(List<CompletionProposal> list, String input, int offset) {
153160
int length = input.length();
154161
//TODO create Model here and pass it as parameter
155-
Model model = ContentFromSources.getDefaultInstances().model;
156-
if (!indexFilesInitialized){ //@since 0.12 context from Orion IndexFiles
162+
if (useNodejsBaseModuleDefinitions){
163+
model = ContentFromSources.getDefaultInstances().model;
164+
}else{
165+
model = new Model();
166+
}
167+
if (useOrionIndexFiles && !indexFilesInitialized){ //@since 0.12 context from Orion IndexFiles
157168
ContentFromOrionIndexFiles.initModel(model);
158169
indexFilesInitialized = true;
159170
}
@@ -177,7 +188,6 @@ private void addCompletionProposalFromModel(List<CompletionProposal> list, Strin
177188
}
178189
}
179190

180-
//TODO
181191
public void addCompletionProposalFromCompletionJson(
182192
List<CompletionProposal> list, String input, int offset) {
183193
//List<CompletionProposal> list = new ArrayList<CompletionProposal>();
@@ -198,7 +208,7 @@ public void addCompletionProposalFromCompletionJson(
198208
//return list;
199209
}
200210

201-
// Entry point
211+
// Entry point for JSDT API call
202212
@Override
203213
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
204214
IDocument doc = viewer.getDocument();
@@ -207,7 +217,7 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
207217
//list = getCompletionProposalFromCompletionJson(inputString , offset);
208218
//addCompletionProposalFromNodejsSources(list, inputString , offset);
209219
addCompletionProposalFromModel(list, inputString , offset);
210-
if (ContentFromCompletionsJson.COMPLETIONS!=null){
220+
if (useCompletionJson && ContentFromCompletionsJson.COMPLETIONS!=null){
211221
addCompletionProposalFromCompletionJson(list, inputString , offset);
212222
}
213223
return (CompletionProposal[]) list.toArray(new CompletionProposal[list.size()]);
@@ -240,9 +250,9 @@ public IContextInformationValidator getContextInformationValidator() {
240250
return null;
241251
}
242252

243-
// private static void debug(String s){
244-
// //NodeclipseConsole.write(s);
245-
// }
253+
// private static void debug(String s){
254+
// //NodeclipseConsole.write(s);
255+
// }
246256
private static void log(String s){
247257
NodeclipseConsole.write(s);
248258
}

org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/NodePreferencePage.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class NodePreferencePage extends FieldEditorPreferencePage implements IWo
2626
private BooleanFieldEditor nodeAllowMany;
2727
private BooleanFieldEditor nodePassAllEnvVars;
2828
private DirectoryFieldEditor nodeSourcesPath;
29+
private BooleanFieldEditor useNodejsBaseModuleDefinitions;
30+
private BooleanFieldEditor useOrionIndexFiles;
31+
private BooleanFieldEditor useCompletionJson;
2932
private FileFieldEditor completionsPath;
3033
private BooleanFieldEditor nodeDebugNoBreak;
3134
private IntegerFieldEditor nodeDebugPort;
@@ -38,8 +41,6 @@ public class NodePreferencePage extends FieldEditorPreferencePage implements IWo
3841
private FileFieldEditor typescriptCompilerPath;
3942
private StringFieldEditor typescriptCompilerOptions;
4043

41-
// private StringFieldEditor nodeclipseVersionsString;
42-
4344
public NodePreferencePage() {
4445
super(GRID);
4546
setPreferenceStore(Activator.getDefault().getPreferenceStore());
@@ -57,12 +58,12 @@ public void init(IWorkbench workbench) {
5758
protected void createFieldEditors() {
5859

5960
//TODO possible to copy version string
60-
// String verString = VersionUtil.getLongString();
61-
// nodeclipseVersionsString = new StringFieldEditor(PreferenceConstants.NODE_OPTIONS, "Node options (node -h):", getFieldEditorParent());
62-
// nodeclipseVersionsString.setStringValue(verString);
63-
// nodeclipseVersionsString.setTextLimit(verString.length());
64-
// nodeclipseVersionsString.setEnabled(false, (Composite) this);
65-
// addField(nodeclipseVersionsString);
61+
// String verString = VersionUtil.getLongString();
62+
// nodeclipseVersionsString = new StringFieldEditor(PreferenceConstants.NODE_OPTIONS, "Node options (node -h):", getFieldEditorParent());
63+
// nodeclipseVersionsString.setStringValue(verString);
64+
// nodeclipseVersionsString.setTextLimit(verString.length());
65+
// nodeclipseVersionsString.setEnabled(false, (Composite) this);
66+
// addField(nodeclipseVersionsString);
6667

6768

6869
nodeclipseConsoleEnabled = new BooleanFieldEditor(PreferenceConstants.NODECLIPSE_CONSOLE_ENABLED,
@@ -93,6 +94,16 @@ protected void createFieldEditors() {
9394
nodeSourcesPath = new DirectoryFieldEditor(PreferenceConstants.NODE_SOURCES_PATH, "Node sources directory path:", getFieldEditorParent());
9495
addField(nodeSourcesPath);
9596

97+
useNodejsBaseModuleDefinitions = new BooleanFieldEditor(PreferenceConstants.USE_NODEJS_BASE_MODULE_DEFINITIONS,
98+
"use Node.js base module definitions (changed after restart)", getFieldEditorParent());
99+
addField(useNodejsBaseModuleDefinitions);
100+
useOrionIndexFiles = new BooleanFieldEditor(PreferenceConstants.USE_ORION_INDEX_FILES,
101+
"use Orion IndexFiles (changed after restart)", getFieldEditorParent());
102+
addField(useOrionIndexFiles);
103+
useCompletionJson = new BooleanFieldEditor(PreferenceConstants.USE_COMPLETIONS_JSON,
104+
"use completion.json (changed after restart)", getFieldEditorParent());
105+
addField(useCompletionJson);
106+
96107
completionsPath = new FileFieldEditor(PreferenceConstants.COMPLETIONS_JSON_PATH, "Alternative completions.json path:", getFieldEditorParent());
97108
addField(completionsPath);
98109

@@ -113,14 +124,14 @@ protected void createFieldEditors() {
113124
coffeePath = new FileFieldEditor(PreferenceConstants.COFFEE_PATH, "Coffee path:", getFieldEditorParent());
114125
addField(coffeePath);
115126

116-
// coffeeJustCoffee = new BooleanFieldEditor(PreferenceConstants.COFFEE_JUST_COFFEE,
117-
// "just coffee (let Node.js find coffee CLI)", getFieldEditorParent());
118-
// addField(coffeeJustCoffee);
127+
// coffeeJustCoffee = new BooleanFieldEditor(PreferenceConstants.COFFEE_JUST_COFFEE,
128+
// "just coffee (let Node.js find coffee CLI)", getFieldEditorParent());
129+
// addField(coffeeJustCoffee);
119130

120131
coffeeCompileOptions = new StringFieldEditor(PreferenceConstants.COFFEE_COMPILE_OPTIONS, "Coffee compile options:", getFieldEditorParent());
121132
addField(coffeeCompileOptions);
122133

123-
coffeeCompileOutputFolder = new StringFieldEditor(PreferenceConstants.COFFEE_COMPILE_OUTPUT_FOLDER, "Coffee output folder Help! #76", getFieldEditorParent());
134+
coffeeCompileOutputFolder = new StringFieldEditor(PreferenceConstants.COFFEE_COMPILE_OUTPUT_FOLDER, "Coffee output folder #76", getFieldEditorParent());
124135
addField(coffeeCompileOutputFolder);
125136

126137
typescriptCompilerPath = new FileFieldEditor(PreferenceConstants.TYPESCRIPT_COMPILER_PATH, "TypeScript compiler path:", getFieldEditorParent());

org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
public class PreferenceConstants {
1010

1111
public static final String NODECLIPSE_CONSOLE_ENABLED = "nodeclipse_console_enabled";
12-
public static final String COMPLETIONS_JSON_PATH = "completionsjson_path";
1312
public static final String NODE_JUST_NODE = "node_just_node";
1413
public static final String NODE_PATH = "node_path";
1514
public static final String NODE_OPTIONS = "node_options";
1615
public static final String NODE_APPLICATION_ARGUMENTS = "node_application_arguments";
1716
public static final String NODE_ALLOW_MANY = "node_allow_many";
1817
public static final String NODE_PASS_ALL_ENVIRONMENT_VARIABLES = "node_pass_all_environment_variables";
1918
public static final String NODE_SOURCES_PATH = "node_sources_lib_path";
19+
public static final String USE_NODEJS_BASE_MODULE_DEFINITIONS = "use_nodejs_base_module_definitions";
20+
public static final String USE_ORION_INDEX_FILES = "use_orion_index_files";
21+
public static final String USE_COMPLETIONS_JSON = "use_completions_json";
22+
public static final String COMPLETIONS_JSON_PATH = "completionsjson_path";
2023
public static final String NODE_DEBUG_NO_BREAK = "node_debug_no_break";
2124
public static final String NODE_DEBUG_PORT = "node_debug_port";
2225
public static final String NODE_MONITOR_PATH = "node_monitor_path";

org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceInitializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public void initializeDefaultPreferences() {
3333

3434
store.setDefault(PreferenceConstants.NODE_ALLOW_MANY, true);
3535

36+
store.setDefault(PreferenceConstants.USE_NODEJS_BASE_MODULE_DEFINITIONS, true);
37+
store.setDefault(PreferenceConstants.USE_ORION_INDEX_FILES, true);
38+
store.setDefault(PreferenceConstants.USE_COMPLETIONS_JSON, true);
39+
3640
//store.setDefault(PreferenceConstants.NODE_DEBUG_NO_BREAK, ""); //default is empty,null,no
3741
store.setDefault(PreferenceConstants.NODE_DEBUG_PORT, "5858");
3842

0 commit comments

Comments
 (0)