Changeset View
Changeset View
Standalone View
Standalone View
src/backends/julia/juliacompletionobject.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This program is free software; you can redistribute it and/or | ||||
3 | * modify it under the terms of the GNU General Public License | ||||
4 | * as published by the Free Software Foundation; either version 2 | ||||
5 | * of the License, or (at your option) any later version. | ||||
6 | * | ||||
7 | * This program is distributed in the hope that it will be useful, | ||||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
10 | * GNU General Public License for more details. | ||||
11 | * | ||||
12 | * You should have received a copy of the GNU General Public License | ||||
13 | * along with this program; if not, write to the Free Software | ||||
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
15 | * Boston, MA 02110-1301, USA. | ||||
16 | * | ||||
17 | * --- | ||||
18 | * Copyright (C) 2016 Ivan Lakhtanov <ivan.lakhtanov@gmail.com> | ||||
19 | */ | ||||
20 | | ||||
21 | #include <QDebug> | ||||
22 | | ||||
23 | #include "juliacompletionobject.h" | ||||
24 | | ||||
25 | #include "juliasession.h" | ||||
26 | #include "juliakeywords.h" | ||||
27 | | ||||
28 | JuliaCompletionObject::JuliaCompletionObject( | ||||
29 | const QString &command, int index, JuliaSession *session) | ||||
30 | : Cantor::CompletionObject(session) | ||||
31 | { | ||||
32 | setLine(command, index); | ||||
33 | } | ||||
34 | | ||||
35 | JuliaCompletionObject::~JuliaCompletionObject() | ||||
36 | { | ||||
37 | } | ||||
38 | | ||||
39 | void JuliaCompletionObject::fetchCompletions() | ||||
40 | { | ||||
41 | auto julia_session = dynamic_cast<JuliaSession *>(session()); | ||||
42 | julia_session->runJuliaCommand( | ||||
43 | QString::fromLatin1( | ||||
44 | "join(" | ||||
45 | "Base.REPL.REPLCompletions.completions(\"%1\", %2)[1]," | ||||
46 | "\"__CANTOR_DELIM__\")" | ||||
47 | ).arg(command()).arg(command().size()) | ||||
48 | ); | ||||
49 | | ||||
50 | auto result = julia_session->getOutput(); | ||||
51 | result.chop(1); | ||||
52 | result.remove(0, 1); | ||||
53 | setCompletions(result.split(QLatin1String("__CANTOR_DELIM__"))); | ||||
54 | | ||||
55 | emit fetchingDone(); | ||||
56 | } | ||||
57 | | ||||
58 | bool JuliaCompletionObject::mayIdentifierContain(QChar c) const | ||||
59 | { | ||||
60 | return c.isLetter() || c.isDigit() || c == QLatin1Char('_') || | ||||
61 | c == QLatin1Char('%') || c == QLatin1Char('$') || c == QLatin1Char('.'); | ||||
62 | } | ||||
63 | | ||||
64 | bool JuliaCompletionObject::mayIdentifierBeginWith(QChar c) const | ||||
65 | { | ||||
66 | return c.isLetter() || c == QLatin1Char('_') || c == QLatin1Char('%') || | ||||
67 | c == QLatin1Char('$'); | ||||
68 | } |