Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DON'T MERGE!!! #478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 85 additions & 77 deletions src/main/java/com/tabnine/binary/BinaryRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,98 +16,106 @@
import com.tabnine.binary.fetch.BinaryVersionFetcher;
import com.tabnine.config.Config;
import com.tabnine.general.StaticConfig;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BinaryRun {
private final BinaryVersionFetcher binaryFetcher;
private final BinaryVersionFetcher binaryFetcher;

public BinaryRun(BinaryVersionFetcher binaryFetcher) {
this.binaryFetcher = binaryFetcher;
}
public BinaryRun(BinaryVersionFetcher binaryFetcher) {
this.binaryFetcher = binaryFetcher;
}

@NotNull
public List<String> generateRunCommand(@Nullable Map<String, Object> additionalMetadata)
throws NoValidBinaryToRunException {
List<String> command = new ArrayList<>(singletonList(binaryFetcher.fetchBinary()));
@NotNull
public List<String> generateRunCommand(@Nullable Map<String, Object> additionalMetadata)
throws NoValidBinaryToRunException {
List<String> command = new ArrayList<>(singletonList(binaryFetcher.fetchBinary()));

command.addAll(getBinaryConstantParameters(additionalMetadata));
command.addAll(getBinaryConstantParameters(additionalMetadata));

return command;
}
return command;
}

public Process reportUninstall(@Nullable Map<String, Object> additionalMetadata)
throws NoValidBinaryToRunException, TabNineDeadException {
String fullLocation = binaryFetcher.fetchBinary();
List<String> command = new ArrayList<>(asList(fullLocation, UNINSTALLING_FLAG));
public Process reportUninstall(@Nullable Map<String, Object> additionalMetadata)
throws NoValidBinaryToRunException, TabNineDeadException {
String fullLocation = binaryFetcher.fetchBinary();
List<String> command = new ArrayList<>(asList(fullLocation, UNINSTALLING_FLAG));

command.addAll(getBinaryConstantParameters(additionalMetadata));
command.addAll(getBinaryConstantParameters(additionalMetadata));

try {
return new ProcessBuilder(command).start();
} catch (IOException e) {
throw new TabNineDeadException(e, fullLocation);
}
}

private ArrayList<String> getBinaryConstantParameters(
@Nullable Map<String, Object> additionalMetadata) {
ArrayList<String> constantParameters = new ArrayList<>();
if (ApplicationManager.getApplication() != null
&& !ApplicationManager.getApplication().isUnitTestMode()) {
List<String> metadata =
new ArrayList<>(
asList(
"--client-metadata",
"pluginVersion=" + cmdSanitize(getTabNinePluginVersion()),
"clientIsUltimate=" + PlatformUtils.isIdeaUltimate(),
"clientChannel=" + Config.CHANNEL,
"pluginUserId=" + PermanentInstallationID.get(),
"debounceValue=" + getDebounceInterval()));
final ApplicationInfo applicationInfo = ApplicationInfo.getInstance();

if (applicationInfo != null) {
constantParameters.add("--client");
constantParameters.add(cmdSanitize(applicationInfo.getVersionName()));
constantParameters.add("--no-lsp");
constantParameters.add("true");

metadata.add("clientVersion=" + cmdSanitize(applicationInfo.getFullVersion()));
metadata.add("clientApiVersion=" + cmdSanitize(applicationInfo.getApiVersion()));
}

if (Config.IS_ON_PREM && StaticConfig.getTabnineEnterpriseHost().isPresent()) {
constantParameters.add(
"--cloud2_url=" + cmdSanitize(StaticConfig.getTabnineEnterpriseHost().get()));
}

if (additionalMetadata != null) {
additionalMetadata.forEach(
(key, value) ->
metadata.add(String.format("%s=%s", key, cmdSanitize(value.toString()))));
}

getLogFilePath()
.ifPresent(
v -> {
constantParameters.add("--log-file-path");
constantParameters.add(v);
});

getLogLevel()
.ifPresent(
v -> {
constantParameters.add("--log-level");
constantParameters.add(v);
});

constantParameters.addAll(metadata);
try {
return new ProcessBuilder(command).start();
} catch (IOException e) {
throw new TabNineDeadException(e, fullLocation);
}
}

return constantParameters;
}
private ArrayList<String> getBinaryConstantParameters(
@Nullable Map<String, Object> additionalMetadata) {
ArrayList<String> constantParameters = new ArrayList<>();
if (ApplicationManager.getApplication() != null
&& !ApplicationManager.getApplication().isUnitTestMode()) {
List<String> metadata =
new ArrayList<>(
asList(
"--client-metadata",
"pluginVersion=" + cmdSanitize(getTabNinePluginVersion()),
"clientIsUltimate=" + PlatformUtils.isIdeaUltimate(),
"clientChannel=" + Config.CHANNEL,
"pluginUserId=" + PermanentInstallationID.get(),
"debounceValue=" + getDebounceInterval()));
final ApplicationInfo applicationInfo = ApplicationInfo.getInstance();

if (applicationInfo != null) {
constantParameters.add("--client");
constantParameters.add(cmdSanitize(applicationInfo.getVersionName()));
constantParameters.add("--no-lsp");
constantParameters.add("true");

metadata.add("clientVersion=" + cmdSanitize(applicationInfo.getFullVersion()));
metadata.add("clientApiVersion=" + cmdSanitize(applicationInfo.getApiVersion()));
}

if (Config.IS_ON_PREM) {

if (StaticConfig.getTabnineEnterpriseHost().isPresent()) {
constantParameters.add(
"--cloud2_url=" + cmdSanitize(StaticConfig.getTabnineEnterpriseHost().get()));
} else {
constantParameters.add(
"--cloud2_url=" + cmdSanitize("https://tabnine.sec.samsung.net"));
}
}

if (additionalMetadata != null) {
additionalMetadata.forEach(
(key, value) ->
metadata.add(String.format("%s=%s", key, cmdSanitize(value.toString()))));
}

getLogFilePath()
.ifPresent(
v -> {
constantParameters.add("--log-file-path");
constantParameters.add(v);
});

getLogLevel()
.ifPresent(
v -> {
constantParameters.add("--log-level");
constantParameters.add(v);
});

constantParameters.addAll(metadata);
}

return constantParameters;
}
}
31 changes: 20 additions & 11 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" ?>
<idea-plugin require-restart="true" url="http://tabnine.com">
<name>Tabnine AI Code Completion- JS Java Python TS Rust Go PHP &amp; More</name>
<name>Tabnine AI Code Completion - JS Java Python TS Rust Go PHP &amp; More</name>
<id>com.tabnine.TabNine</id>
<vendor email="support@tabnine.com" url="https://tabnine.com">Tabnine</vendor>
<description><![CDATA[
Expand Down Expand Up @@ -101,8 +101,8 @@
<p>
More resources: <a href="https://www.tabnine.com/blog">Tabnine blog</a>, <a href="https://www.tabnine.com/academy">Tabnine Academy</a> <a href="https://www.tabnine.com/faq">Questions? Check out our FAQ</a>, <a href="https://www.tabnine.com/pricing">Learn more about our premium plans</a>.
</p>
]]>
</description>
]]>
</description>

<change-notes>Tabnine is always evolving. Most updates are in the binary sidecar.</change-notes>

Expand All @@ -115,30 +115,39 @@
<postStartupActivity implementation="com.tabnine.Initializer"/>
<statusBarWidgetProvider implementation="com.tabnine.statusBar.StatusBarProvider"/>
<statusBarWidgetProvider implementation="com.tabnine.statusBar.StatusBarPromotionProvider"/>
<completion.contributor language="any" implementationClass="com.tabnine.intellij.completions.TabNineCompletionContributor" order="first"/>
<completion.contributor language="any"
implementationClass="com.tabnine.intellij.completions.TabNineCompletionContributor"
order="first"/>

<applicationService serviceImplementation="com.tabnine.lifecycle.BinaryStateService"/>
<applicationService serviceImplementation="com.tabnine.capabilities.CapabilitiesService"/>
<applicationService serviceImplementation="com.tabnine.lifecycle.LifeCycleHelper"/>
<applicationService serviceImplementation="com.tabnine.general.BrowserUtilsService"/>

<actionPromoter implementation="com.tabnine.inline.InlineActionsPromoter"/>
<editorActionHandler action="EditorEscape" implementationClass="com.tabnine.inline.EscapeHandler" id="previewEscape" order="before hide-hints"/>
<editorActionHandler action="EditorEscape" implementationClass="com.tabnine.inline.EscapeHandler"
id="previewEscape" order="before hide-hints"/>
<editorFactoryDocumentListener implementation="com.tabnine.inline.TabnineDocumentListener"/>
<applicationService serviceImplementation="com.tabnine.userSettings.AppSettingsState"/>
<applicationConfigurable parentId="tools" instance="com.tabnine.userSettings.AppSettingsConfigurable" id="com.tabnine.userSettings.AppSettingsConfigurable" displayName="Tabnine"/>
<fileType name="Tabnine project model file" implementationClass="com.tabnine.TabnineProjectModelFileType" extensions="tabnine,.tabnine,tabnine.model,.tabnine.model,model,.model"/>
<fileType name="Tabnine ignore file" implementationClass="com.tabnine.TabnineIgnoreFileType" extensions="tabnineignore"/>
<applicationConfigurable parentId="tools" instance="com.tabnine.userSettings.AppSettingsConfigurable"
id="com.tabnine.userSettings.AppSettingsConfigurable" displayName="Tabnine"/>
<fileType name="Tabnine project model file" implementationClass="com.tabnine.TabnineProjectModelFileType"
extensions="tabnine,.tabnine,tabnine.model,.tabnine.model,model,.model"/>
<fileType name="Tabnine ignore file" implementationClass="com.tabnine.TabnineIgnoreFileType"
extensions="tabnineignore"/>
</extensions>

<actions>
<action class="com.tabnine.inline.ShowNextTabnineInlineCompletionAction" id="ShowNextTabnineInlineCompletionAction" text="Show Next Inline Completion">
<action class="com.tabnine.inline.ShowNextTabnineInlineCompletionAction"
id="ShowNextTabnineInlineCompletionAction" text="Show Next Inline Completion">
<keyboard-shortcut first-keystroke="alt CLOSE_BRACKET" keymap="$default"/>
</action>
<action class="com.tabnine.inline.ShowPreviousTabnineInlineCompletionAction" id="ShowPreviousTabnineInlineCompletionAction" text="Show Previous Inline Completion">
<action class="com.tabnine.inline.ShowPreviousTabnineInlineCompletionAction"
id="ShowPreviousTabnineInlineCompletionAction" text="Show Previous Inline Completion">
<keyboard-shortcut first-keystroke="alt OPEN_BRACKET" keymap="$default"/>
</action>
<action class="com.tabnine.inline.AcceptTabnineInlineCompletionAction" id="AcceptTabnineInlineCompletionAction" text="Accept Inline Completion">
<action class="com.tabnine.inline.AcceptTabnineInlineCompletionAction" id="AcceptTabnineInlineCompletionAction"
text="Accept Inline Completion">
<keyboard-shortcut first-keystroke="TAB" keymap="$default"/>
</action>
</actions>
Expand Down