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 "juliacompletionobject.h" | ||||
22 | | ||||
23 | #include "juliasession.h" | ||||
24 | #include "juliakeywords.h" | ||||
25 | | ||||
26 | JuliaCompletionObject::JuliaCompletionObject( | ||||
27 | const QString &command, int index, JuliaSession *session) | ||||
28 | : Cantor::CompletionObject(session) | ||||
29 | { | ||||
30 | setLine(command, index); | ||||
31 | } | ||||
32 | | ||||
33 | JuliaCompletionObject::~JuliaCompletionObject() | ||||
34 | { | ||||
35 | } | ||||
36 | | ||||
37 | void JuliaCompletionObject::fetchCompletions() | ||||
38 | { | ||||
39 | auto julia_session = dynamic_cast<JuliaSession *>(session()); | ||||
40 | julia_session->runJuliaCommand( | ||||
41 | QString::fromLatin1( | ||||
42 | "join(" | ||||
43 | "Base.REPL.REPLCompletions.completions(\"%1\", %2)[1]," | ||||
44 | "\"__CANTOR_DELIM__\")" | ||||
45 | ).arg(command()).arg(command().size()) | ||||
46 | ); | ||||
47 | | ||||
48 | auto result = julia_session->getOutput(); | ||||
49 | result.chop(1); | ||||
50 | result.remove(0, 1); | ||||
51 | setCompletions(result.split(QLatin1String("__CANTOR_DELIM__"))); | ||||
52 | | ||||
53 | emit fetchingDone(); | ||||
54 | } | ||||
55 | | ||||
56 | bool JuliaCompletionObject::mayIdentifierContain(QChar c) const | ||||
57 | { | ||||
58 | return c.isLetter() || c.isDigit() || c == QLatin1Char('_') || | ||||
59 | c == QLatin1Char('%') || c == QLatin1Char('$') || c == QLatin1Char('.'); | ||||
60 | } | ||||
61 | | ||||
62 | bool JuliaCompletionObject::mayIdentifierBeginWith(QChar c) const | ||||
63 | { | ||||
64 | return c.isLetter() || c == QLatin1Char('_') || c == QLatin1Char('%') || | ||||
65 | c == QLatin1Char('$'); | ||||
66 | } |