Skip to content

Commit 168d7ab

Browse files
committed
move cursor to error index when user click diagnostic
1 parent 98be1aa commit 168d7ab

File tree

11 files changed

+73
-9
lines changed

11 files changed

+73
-9
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/GCCCompiler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public ShellResult compile(File[] sourceFiles) {
6464
flags.add("-Og");
6565
flags.add("-o");
6666
flags.add(new File(internalDir.getAbsolutePath(), GCCConstants.TEMP_BINARY_NAME).getAbsolutePath());
67+
flags.addAll(getUserFlags());
6768

6869
String TEMPEnv = new File(gccDir, GCCConstants.BUILD_DIR).getAbsolutePath();
6970
String PATHEnv =
@@ -81,4 +82,10 @@ public ShellResult compile(File[] sourceFiles) {
8182
envMap.put("TEMP", TEMPEnv);
8283
return ShellUtils.execCommand(compilerPath, flags, envMap);
8384
}
85+
86+
private ArrayList<String> getUserFlags() {
87+
ArrayList<String> flags = new ArrayList<>();
88+
flags.add("-fdiagnostics-show-location=every-line");
89+
return flags;
90+
}
8491
}

app/src/main/java/com/duy/ccppcompiler/compiler/diagnostic/Kind.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package com.duy.ccppcompiler.compiler.diagnostic;
1818

19+
/**
20+
* https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Diagnostic-Message-Formatting-Options.html
21+
* https://gcc.gnu.org/onlinedocs/gcc-3.3.5/gnat_ug_unx/Output-and-Error-Message-Control.html
22+
*/
1923
public enum Kind {
2024
/**
2125
* Problem which prevents the tool's normal completion.

app/src/main/java/com/duy/ccppcompiler/compiler/diagnostic/OutputParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
import java.util.regex.Pattern;
2121

2222
/**
23+
* https://gcc.gnu.org/onlinedocs/gcc-3.3.5/gnat_ug_unx/Output-and-Error-Message-Control.html
24+
* <p>
25+
* https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Diagnostic-Message-Formatting-Options.html
26+
* <p>
2327
* Created by Duy on 28-Apr-18.
2428
*/
2529

app/src/main/java/com/duy/ccppcompiler/diagnostic/DiagnosticFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static DiagnosticFragment newInstance() {
5555
@Nullable
5656
@Override
5757
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
58-
return inflater.inflate(R.layout.fragment_diagnostic, container, false);
58+
return inflater.inflate(R.layout.fragment_diagnostic, container, false);
5959

6060
}
6161

app/src/main/java/com/duy/ccppcompiler/diagnostic/DiagnosticPresenter.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@
2020
import android.view.View;
2121

2222
import com.duy.ccppcompiler.compiler.diagnostic.Diagnostic;
23+
import com.duy.common.DLog;
24+
import com.jecelyin.editor.v2.common.Command;
2325
import com.jecelyin.editor.v2.ui.activities.EditorActivity;
26+
import com.jecelyin.editor.v2.ui.editor.EditorDelegate;
2427
import com.jecelyin.editor.v2.ui.manager.TabManager;
2528
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
2629

30+
import java.io.File;
2731
import java.util.ArrayList;
2832

2933
/**
3034
* Created by Duy on 28-Apr-18.
3135
*/
3236

3337
public class DiagnosticPresenter implements DiagnosticContract.Presenter {
38+
private static final String TAG = "DiagnosticPresenter";
3439
private final EditorActivity mActivity;
3540
private final TabManager mTabManager;
3641
private ArrayList<Diagnostic> diagnostics;
@@ -48,7 +53,22 @@ public DiagnosticPresenter(DiagnosticContract.View view, EditorActivity activity
4853
@MainThread
4954
@Override
5055
public void onDiagnosticClick(View view, Diagnostic diagnostic) {
51-
// TODO: 28-Apr-18 implement
56+
if (DLog.DEBUG)
57+
DLog.d(TAG, "onDiagnosticClick() called with: view = [" + view + "], diagnostic = [" + diagnostic + "]");
58+
Object source = diagnostic.getSource();
59+
if (source instanceof File) {
60+
File file = (File) source;
61+
EditorDelegate editorDelegate = mTabManager.getEditorDelegate(file);
62+
if (editorDelegate != null) {
63+
Command command = new Command(Command.CommandEnum.GOTO_LINE_COL);
64+
command.args.putInt("line", (int) diagnostic.getLineNumber());
65+
command.args.putInt("col", (int) diagnostic.getColumnNumber());
66+
editorDelegate.doCommand(command);
67+
} else {
68+
mTabManager.newTab(file);
69+
onDiagnosticClick(view, diagnostic);
70+
}
71+
}
5272
}
5373

5474
@Override
@@ -57,7 +77,7 @@ public void showView() {
5777
}
5878

5979
@Override
60-
public void hideView(){
80+
public void hideView() {
6181
mActivity.mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
6282
}
6383

app/src/main/java/com/jecelyin/editor/v2/common/Command.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public enum CommandEnum {
4747
SELECT_ALL,
4848
DUPLICATION,
4949
CONVERT_WRAP_CHAR,
50-
GOTO_LINE,
50+
GOTO_LINE_COL,
5151
FIND,
5252
GOTO_TOP,
5353
GOTO_END,

app/src/main/java/com/jecelyin/editor/v2/ui/dialog/GotoLineDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void show() {
4242
public void onConfirm(CharSequence input) {
4343
try {
4444
int line = StringUtils.toInt(input.toString());
45-
Command command = new Command(Command.CommandEnum.GOTO_LINE);
45+
Command command = new Command(Command.CommandEnum.GOTO_LINE_COL);
4646
command.args.putInt("line", line);
4747
getMainActivity().doCommand(command);
4848
} catch (Exception e) {

app/src/main/java/com/jecelyin/editor/v2/ui/editor/EditorDelegate.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,10 @@ public boolean doCommand(Command command) {
273273
if (!readonly)
274274
mEditText.convertWrapCharTo((String) command.object);
275275
break;
276-
case GOTO_LINE:
277-
mEditText.gotoLine(command.args.getInt("line"));
276+
case GOTO_LINE_COL:
277+
int col = command.args.getInt("col", -1);
278+
int line = command.args.getInt("line", -1);
279+
mEditText.gotoLine(line, col);
278280
break;
279281
case GOTO_TOP:
280282
mEditText.gotoTop();

app/src/main/java/com/jecelyin/editor/v2/ui/manager/TabManager.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.jecelyin.editor.v2.ui.manager;
2020

2121
import android.database.DataSetObserver;
22+
import android.support.annotation.Nullable;
2223
import android.support.v4.view.GravityCompat;
2324
import android.support.v4.view.ViewPager;
2425
import android.view.View;
@@ -231,4 +232,21 @@ public void onClose(String path, String encoding, int offset) {
231232
public IEditorPagerAdapter getEditorPagerAdapter() {
232233
return mEditorFragmentPagerAdapter;
233234
}
235+
236+
/**
237+
* Get current editor edit file
238+
*
239+
* @return null if not found
240+
*/
241+
@Nullable
242+
public EditorDelegate getEditorDelegate(File file) {
243+
String path = file.getPath();
244+
ArrayList<EditorDelegate> allEditor = mEditorFragmentPagerAdapter.getAllEditor();
245+
for (EditorDelegate editorDelegate : allEditor) {
246+
if (editorDelegate.getPath().equals(path)) {
247+
return editorDelegate;
248+
}
249+
}
250+
return null;
251+
}
234252
}

app/src/main/java/com/jecelyin/editor/v2/ui/widget/menu/MenuFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void initAllMenuItem() {
113113
menuItemInfos.add(new MenuItemInfo(MenuGroup.FIND, R.id.m_find_replace, Command.CommandEnum.FIND, R.drawable.ic_find_in_page_white_24dp, R.string.find_or_replace));
114114
menuItemInfos.add(new MenuItemInfo(MenuGroup.FIND, R.id.m_goto_top, Command.CommandEnum.GOTO_TOP, R.drawable.ic_vertical_align_top_white_24dp, R.string.jump_to_start));
115115
menuItemInfos.add(new MenuItemInfo(MenuGroup.FIND, R.id.m_goto_end, Command.CommandEnum.GOTO_END, R.drawable.ic_vertical_align_bottom_white_24dp, R.string.jump_to_end));
116-
menuItemInfos.add(new MenuItemInfo(MenuGroup.FIND, R.id.m_goto_line, Command.CommandEnum.GOTO_LINE, R.drawable.m_goto_line, R.string.goto_line));
116+
menuItemInfos.add(new MenuItemInfo(MenuGroup.FIND, R.id.m_goto_line, Command.CommandEnum.GOTO_LINE_COL, R.drawable.m_goto_line, R.string.goto_line));
117117
menuItemInfos.add(new MenuItemInfo(MenuGroup.FIND, R.id.m_back, Command.CommandEnum.BACK, R.drawable.ic_arrow_back_white_24dp, R.string.back));
118118
menuItemInfos.add(new MenuItemInfo(MenuGroup.FIND, R.id.m_forward, Command.CommandEnum.FORWARD, R.drawable.ic_arrow_forward_white_24dp, R.string.forward));
119119

0 commit comments

Comments
 (0)