Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: combinatorial/AppCodeDashSearch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: gdelmas/IntelliJDashPlugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Nov 13, 2013

  1. use file extension as keyword

    this way dash can be configured to show the right docsets
    gdelmas committed Nov 13, 2013
    Copy the full SHA
    bb5ce5d View commit details
  2. Copy the full SHA
    89121e9 View commit details
  3. Copy the full SHA
    4d4b802 View commit details
  4. updated readme

    gdelmas committed Nov 13, 2013
    Copy the full SHA
    77290ab View commit details

Commits on Nov 18, 2013

  1. Update README.txt

    Kapeli committed Nov 18, 2013
    Copy the full SHA
    70a23e3 View commit details
  2. Merge pull request #3 from Kapeli/master

    Link to kapeli.com instead of App Store
    gdelmas committed Nov 18, 2013
    Copy the full SHA
    651a494 View commit details
  3. Copy the full SHA
    fb69ce3 View commit details

Commits on Nov 24, 2013

  1. added ruby syntax support

    gdelmas committed Nov 24, 2013
    Copy the full SHA
    befe780 View commit details
  2. Copy the full SHA
    e84c00b View commit details
  3. Copy the full SHA
    387d276 View commit details
  4. Update README.txt

    gdelmas committed Nov 24, 2013
    Copy the full SHA
    2d91148 View commit details
  5. Update README.txt

    gdelmas committed Nov 24, 2013
    Copy the full SHA
    7af235e View commit details

Commits on Nov 25, 2013

  1. Copy the full SHA
    1e74c6b View commit details

Commits on Nov 26, 2013

  1. Better defaults for Android Studio.

    If this plugin is configured to run under Android Studio there is no
    real need to have Java files use the Java docset whilst the Android
    docset is a much better fit (as it is a superset of Java's anyway).
    agatti committed Nov 26, 2013
    Copy the full SHA
    411444b View commit details

Commits on Nov 29, 2013

  1. Fix Java keywords

    Kapeli committed Nov 29, 2013
    Copy the full SHA
    c122c6d View commit details
  2. Merge pull request #7 from Kapeli/master

    Fix Java keywords
    gdelmas committed Nov 29, 2013
    Copy the full SHA
    ecae704 View commit details

Commits on Dec 1, 2013

  1. Merge https://github.com/gdelmas/IntelliJDashPlugin

    Conflicts:
    	src/de/dreamlab/dash/KeywordLookup.java
    agatti committed Dec 1, 2013
    Copy the full SHA
    4fb2551 View commit details

Commits on Dec 2, 2013

  1. Avoid potential NPE in isIdentifierPart.

    If the VirtualFile instance is null, isIdentifierPart attempts to
    compare fileType to the Ruby file type identifier, but the way the
    string comparison is executed will trigger an NPE instead of just having
    isIdentifierPart return false.
    agatti committed Dec 2, 2013
    Copy the full SHA
    42961cb View commit details

Commits on Dec 9, 2013

  1. Merge pull request #4 from agatti/master

    Better defaults for Android Studio.
    gdelmas committed Dec 9, 2013
    Copy the full SHA
    001c396 View commit details
  2. fix conflicts from #4

    gdelmas committed Dec 9, 2013
    Copy the full SHA
    4ad2e49 View commit details
  3. Copy the full SHA
    3f1013f View commit details
  4. fixing fileType issue

    gdelmas committed Dec 9, 2013
    Copy the full SHA
    019844e View commit details

Commits on Dec 15, 2013

  1. updated plugin description

    gdelmas committed Dec 15, 2013
    Copy the full SHA
    785ca6c View commit details

Commits on Jan 29, 2014

  1. Copy the full SHA
    579ff39 View commit details

Commits on Apr 5, 2014

  1. context sensitive search

    gdelmas committed Apr 5, 2014
    Copy the full SHA
    2260f5e View commit details
  2. added beta notes to readme

    gdelmas committed Apr 5, 2014
    Copy the full SHA
    4b76fef View commit details

Commits on Apr 23, 2014

  1. better language context list debug output

    needed in development for keyword to context mapping
    gdelmas committed Apr 23, 2014
    Copy the full SHA
    aecf235 View commit details
  2. Copy the full SHA
    5b89d63 View commit details
  3. Copy the full SHA
    a62fb77 View commit details
  4. Copy the full SHA
    d2bf8a0 View commit details
  5. Copy the full SHA
    e8685f9 View commit details

Commits on Apr 24, 2014

  1. added missing ruby mapping

    gdelmas committed Apr 24, 2014
    Copy the full SHA
    1b6e7ba View commit details
  2. Copy the full SHA
    abb45cf View commit details
  3. Copy the full SHA
    91e2cf1 View commit details
  4. Copy the full SHA
    e9d8620 View commit details

Commits on May 1, 2014

  1. avoid potential NPE

    gdelmas committed May 1, 2014
    Copy the full SHA
    3d1223c View commit details

Commits on May 6, 2014

  1. Copy the full SHA
    d594c10 View commit details
  2. updated .gitignore

    gdelmas committed May 6, 2014
    Copy the full SHA
    119b0e8 View commit details

Commits on May 11, 2014

  1. changed required idea version

    gdelmas committed May 11, 2014
    Copy the full SHA
    3ddfa3b View commit details
  2. Update README.md

    Kapeli committed May 11, 2014
    Copy the full SHA
    595cda4 View commit details
  3. Merge pull request #20 from Kapeli/master

    AppCode 1.x install instructions in readme
    gdelmas committed May 11, 2014
    Copy the full SHA
    701615d View commit details
  4. Copy the full SHA
    a925e10 View commit details

Commits on May 16, 2014

  1. Dash 2.1 keywords

    Bogdan Popescu committed May 16, 2014
    Copy the full SHA
    d6b8fb1 View commit details
  2. Merge pull request #21 from Kapeli/master

    Dash 2.1 keywords
    gdelmas committed May 16, 2014
    Copy the full SHA
    70d556c View commit details
  3. updated project iml

    gdelmas committed May 16, 2014
    Copy the full SHA
    637eade View commit details

Commits on May 17, 2014

  1. updated language list & added more languages context support

    - Bash
    - Go
    - Haskell
    - Lua
    - Markdown
    - Scala
    - TypoScript
    gdelmas committed May 17, 2014
    Copy the full SHA
    97d9de2 View commit details
  2. added angularjs to keywords

    fixes #22
    gdelmas committed May 17, 2014
    Copy the full SHA
    db66a08 View commit details

Commits on Jun 2, 2014

  1. Better integration for Android projects.

    Instead of just relying on the IDE product code, this checks the
    project's assigned SDK and picks an Android-oriented keyword lookup
    object instance.  This is needed since recent IntelliJ versions allow
    creating Android projects as well as normal Java ones.
    
    As a bonus, the default keyword lookup dataset now contains more
    appropriate keywords for JSP/JSPX pages.
    agatti authored and gdelmas committed Jun 2, 2014
    Copy the full SHA
    0f80be6 View commit details
  2. New SDK detection logic in place.

    agatti authored and gdelmas committed Jun 2, 2014
    Copy the full SHA
    8ff1dd9 View commit details

Commits on Jun 3, 2014

  1. sdk context detection

    gdelmas committed Jun 3, 2014
    Copy the full SHA
    0c203fc View commit details
Showing with 1,308 additions and 127 deletions.
  1. +73 −1 .gitignore
  2. +4 −3 Dash.iml
  3. +9 −0 LICENSE.md
  4. +75 −12 META-INF/plugin.xml
  5. +44 −0 README.md
  6. +0 −13 README.txt
  7. BIN resources/dash.png
  8. BIN resources/dash@2x.png
  9. +0 −98 src/com/paperetto/dash/DashLauncherAction.java
  10. +57 −0 src/de/dreamlab/dash/AbstractMenuAction.java
  11. +176 −0 src/de/dreamlab/dash/KeywordLookup.java
  12. +98 −0 src/de/dreamlab/dash/LookupInfoDictionary.java
  13. +27 −0 src/de/dreamlab/dash/SearchAction.java
  14. +217 −0 src/de/dreamlab/dash/SearchService.java
  15. +33 −0 src/de/dreamlab/dash/SmartSearchAction.java
  16. +35 −0 src/de/dreamlab/dash/SystemUtil.java
  17. +56 −0 src/de/dreamlab/dash/keywords/AbstractSdkKeyword.java
  18. +28 −0 src/de/dreamlab/dash/keywords/ExcludeFileTypeKeyword.java
  19. +28 −0 src/de/dreamlab/dash/keywords/ExcludeSdkTypeKeyword.java
  20. +43 −0 src/de/dreamlab/dash/keywords/FileTypeSpecificKeyword.java
  21. +9 −0 src/de/dreamlab/dash/keywords/IKeyword.java
  22. +44 −0 src/de/dreamlab/dash/keywords/JavaSdkVersionDependentKeyword.java
  23. +15 −0 src/de/dreamlab/dash/keywords/Keyword.java
  24. +34 −0 src/de/dreamlab/dash/keywords/PythonSdkVersionDependentKeyword.java
  25. +42 −0 src/de/dreamlab/dash/keywords/SdkTypeSpecificKeyword.java
  26. +69 −0 src/de/dreamlab/dash/keywords/SqlDialectDependentKeyword.java
  27. +51 −0 src/de/dreamlab/dash/launcher/AbstractLauncher.java
  28. +21 −0 src/de/dreamlab/dash/launcher/DashLauncher.java
  29. +20 −0 src/de/dreamlab/dash/launcher/DashPluginSchemeLauncher.java
74 changes: 73 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,73 @@
.DS_Store
# Created by http://www.gitignore.io

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Xcode ###
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.xcuserstate


### AppCode ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

## Directory-based project format
.idea/
# if you remove the above rule, at least ignore user-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# and these sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml

## File-based project format
*.ipr
*.iws
*.iml

## Additional for IntelliJ
out/

# generated by mpeltonen/sbt-idea plugin
.idea_modules/

# generated by JIRA plugin
atlassian-ide-plugin.xml

# generated by Crashlytics plugin (for Android Studio and Intellij)
com_crashlytics_export_strings.xml
7 changes: 4 additions & 3 deletions Dash.iml
Original file line number Diff line number Diff line change
@@ -5,9 +5,10 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="jdk" jdkName="IDEA IC-122.SNAPSHOT" jdkType="IDEA JDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="PROVIDED" name="sql" level="project" />
</component>
</module>

</module>
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2013-2018 Gerard Delmàs and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
87 changes: 75 additions & 12 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,84 @@
<idea-plugin version="2">
<id>com.paperetto.dash</id>
<name>Dash Launcher</name>
<version>1.0</version>
<vendor email="dash-plugin@paperetto.com" url="http://www.linkedin.com/in/combinatorial">David Brittain</vendor>
<name>Dash</name>
<version>3.3</version>
<vendor url="https://github.com/gdelmas/IntelliJDashPlugin">Gerard Delmàs</vendor>

<description><![CDATA[
Launches Dash with the word under the caret or the selected text<br>
Dash is a Mac OSX utility that can be obtained from the <a href="http://itunes.apple.com/us/app/dash/id458034879?ls=1&mt=12">Apple Store</a>
]]></description>
<p>A smart and simple plugin that provides keyboard shortcut access for Dash, Velocity or Zeal in IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, PyCharm, DataGrip, CLion, GoLand and Android Studio.</p>
<p><h2><b>Usage</b></h2></p>
<p>The default <b>shortcut</b> assigned to smart-search is <b>Cmd-Shift-D</b> (Mac OS X) or <b>Ctrl-Shift-D</b> (Windows, Linux).</p>
<p>A <b>menubar command</b> named either "<b>Smart-Search Documentation</b>" can be found in the "Tools" menu.</p>
<p>The plugin either searches for the statement at caret position or the current selection. It will identify the programming language in use and request filtered results accordingly. A non filtered search over all documentation entries can be invoked by adding the <b>Alt</b> modifier key to the shortcut. "<b>Search all Documentation</b>" is also available in the tools menu.
<p><h2><b>Configuration</b></h2></p>
<h3><b>Shortcut</b></h3>
<p>You can change the shortcut at Preferences -&gt; Keymap -&gt; Plug-ins -&gt; Dash.</p>
<h3><b>Toolbar Icon</b></h3>
<p>You can add a button to the toolbar. Right-click the menubar -&gt; Customize […]. You will find the button under "Plug-ins -&gt; Dash".</p>
<p><h2><b>Supported API Documentation Browsers</b></h2></p>
<h3><b>Kapeli Dash (Mac OS X)</b></h3>
<p>Dash is an API Documentation Browser and Code Snippet Manager. Dash stores snippets of code and instantly searches offline documentation sets for 150+ APIs (for a full list, see below). You can even generate your own docsets or request docsets to be included. <a href="http://kapeli.com/dash">http://kapeli.com/dash</a></p>
<h3><b>Velocity (Windows)</b></h3>
<p>Velocity gives your Windows desktop offline access to over 150 API documentation sets (provided by Dash for OS X). <a href="https://velocity.silverlakesoftware.com">https://velocity.silverlakesoftware.com</a></p>
<h3><b>Zeal (Linux &amp; Windows)</b></h3>
<p>Zeal is a simple offline API documentation browser inspired by Dash (OS X app). <a href="http://zealdocs.org">http://zealdocs.org</a></p>
]]></description>

<change-notes><![CDATA[
Initial release<br>
]]>
<pre>
3.3
- Added non-smart "Search all Documentation" option
- Java 9 SDK detection
3.2.5
- Fixed Zeal Support
- Go, Elixir & Erlang support
3.2.4
- Dockerfile support
3.2.3
- Dash 2.3 Remote redirection support
- Clojure support
3.2.2 ActionScript support
3.2.1 Fixed an issue where
context filters would not work
3.2
- Toolbar icon support
- Velocity support on Windows
- Zeal support on Linux
3.1
- language detection support in strings
- project settings sql dialect will be used
to filter search results
- android project support
- java search results according to projects
sdk version
- python search results according to
projects sdk version
- added language support for: Bash, Go,
Haskell, Lua, Markdown, Scala, TypoScript
- extended language support for: angularjs,
momen, require, awsjs, jasmine, sinon,
tornado, sqlalchemy, numpy, scipy, salt,
polymerdart, angulardart
- performance and stability improvements
3.0.1 Fixed missing Ruby context recognition
3.0 Added Context aware search
2.2 Compatibility and stability fixes
2.1 Added Ruby syntax support, stability fixes
2.0 Added Dash docset keyword support
</pre>
]]>
</change-notes>

<!-- please see http://confluence.jetbrains.net/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="107.105"/>
<idea-version since-build="123.72"/>

<!-- please see http://confluence.jetbrains.net/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
<depends>com.intellij.modules.lang</depends>
<depends optional="true">com.intellij.sql</depends>

<application-components>
<!-- Add your application components here -->
@@ -31,14 +90,18 @@

<actions>
<!-- Add your actions here -->
<action id="DashLauncherAction" class="com.paperetto.dash.DashLauncherAction" text="Search in Dash"
description="Searches word under caret in Google">
<action id="SmartSearchAction" class="de.dreamlab.dash.SmartSearchAction" text="Smart-Search Documentation" description="Searches word under caret or selection in documentation filtered by currently used language">
<add-to-group group-id="ToolsMenu" anchor="last"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift D"/>
</action>

<action id="SearchAction" class="de.dreamlab.dash.SearchAction" text="Search all Documentation" description="Searches word under caret or selection in documentation">
<add-to-group group-id="ToolsMenu" anchor="last"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt shift D"/>
</action>
</actions>

<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>
</idea-plugin>
</idea-plugin>
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
A smart and simple plugin that provides keyboard shortcut access for Dash, Velocity or Zeal in IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, PyCharm, DataGrip, CLion, GoLand and Android Studio.

## Installation
To install the plugin in your IDE go to **Preferences -> Plugins -> Browse repositories** and **search for "Dash"**.

## Usage
The default **shortcut** assigned to smart-search is **Cmd-Shift-D** (Mac OS X) or **Ctrl-Shift-D** (Windows, Linux).


A **menubar command** named "**Smart-Search Documentation**" can be found in the "Tools" menu.


The plugin either searches for the statement at caret position or the current selection. It will identify the programming language in use and request filtered results accordingly. A non filtered search over all documentation entries can be invoked by adding the **Alt** modifier key to the shortcut. "**Search all Documentation**" is also available in the tools menu.

## Configuration
### Shortcut
You can change the shortcut at Preferences -> Keymap -> Plug-ins -> Dash.

### Toolbar Icon
You can add a button to the toolbar. Right-click the menubar -> Customize []. You will find the button under "Plug-ins -> Dash".

## Supported API Documentation Browsers
### Kapeli Dash (Mac OS X)
Dash is an API Documentation Browser and Code Snippet Manager. Dash stores snippets of code and instantly searches offline documentation sets for 150+ APIs (for a full list, see below). You can even generate your own docsets or request docsets to be included.
[http://kapeli.com/dash](http://kapeli.com/dash)

### Velocity (Windows)
Velocity gives your Windows desktop offline access to over 150 API documentation sets (provided by Dash for OS X).
[https://velocity.silverlakesoftware.com](https://velocity.silverlakesoftware.com)

### Zeal (Linux & Windows)
Zeal is a simple offline API documentation browser inspired by Dash (OS X app).
[http://zealdocs.org](http://zealdocs.org)


## Troubleshooting
###### On Windows, when using Zeal the IDE shows `Failed to open dash-plugin://...` in the Event Log
It looks like the URL handler has not been registered for Zeal. Please run `zeal.exe --register`.

###### The plugin does not work on old IDEs
Older IDE versions like **AppCode 1.x** are not supported anymore. Please manually install version 2.2 of the plugin: https://github.com/gdelmas/IntelliJDashPlugin/releases/tag/2.2

###### In rare conditions the installation from the repositories does not work
It looks like there is an IntelliJ/Java bug with OS X Mavericks which prevents to install plugins from the repositories. Please install the plugin manually from [here](https://github.com/gdelmas/IntelliJDashPlugin/releases). For additional information check [issue #13](https://github.com/gdelmas/IntelliJDashPlugin/issues/13).
13 changes: 0 additions & 13 deletions README.txt

This file was deleted.

Binary file added resources/dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/dash@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 0 additions & 98 deletions src/com/paperetto/dash/DashLauncherAction.java

This file was deleted.

57 changes: 57 additions & 0 deletions src/de/dreamlab/dash/AbstractMenuAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package de.dreamlab.dash;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.util.IconLoader;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.swing.*;

abstract public class AbstractMenuAction extends AnAction {
protected @Nonnull String title = "";
protected @Nonnull String description = "";
protected @Nullable String iconFilename = null;


private boolean isPresentationInitialized = false;

private void initPresentation()
{
String docAppName = "";

if ( SystemUtil.isIsOSMac() ) {
docAppName = " in Dash";
}

Presentation presentation = this.getTemplatePresentation();
presentation.setText(title + docAppName);
presentation.setDescription(description + docAppName);

if ( iconFilename != null ) {
Icon icon = IconLoader.getIcon("/" + iconFilename, AbstractMenuAction.class);
presentation.setIcon(icon);
}
}

@Override
public void update(AnActionEvent e) {
super.update(e);

Presentation presentation = e.getPresentation();

if ( !isPresentationInitialized ) {
isPresentationInitialized = true;
initPresentation();

Presentation templatePresentation = getTemplatePresentation();
presentation.setText(templatePresentation.getText());
presentation.setDescription(templatePresentation.getDescription());
presentation.setIcon(templatePresentation.getIcon());
}

presentation.setEnabled(PlatformDataKeys.EDITOR.getData(e.getDataContext()) != null);
}
}
176 changes: 176 additions & 0 deletions src/de/dreamlab/dash/KeywordLookup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package de.dreamlab.dash;

import com.intellij.lang.Language;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import de.dreamlab.dash.keywords.*;

import java.util.*;

public class KeywordLookup {
private HashMap<String, List<IKeyword>> languageMap;

public KeywordLookup()
{
languageMap = new HashMap<String, List<IKeyword>>();

// IntelliJ Ultimate Edition 13.1, WebStorm 8.0, PhpStorm 7.1, RubyMine 6.3, PyCharm 3.1
setLanguage("HTML", "html", "angularjs");
setLanguage("XHTML", "html");
setLanguage("XML", "xml");
setLanguage("XPath", "xml"); // not RubyMine, not PyCharm
setLanguage("RegExp", "regex");

// IntelliJ Ultimate Edition 13.1, WebStorm 8.0, PhpStorm 7.1, RubyMine 6.3, PyCharm 3.1
setLanguage("CSS", "css");
setLanguage("JQuery-CSS", "css", "jquery", "jqueryui", "jquerym");
setLanguage("LESS", "less", "css");
setLanguage("SASS", "sass", "compass", "bourbon", "neat", "css");
setLanguage("SCSS", "sass", "compass", "bourbon", "neat", "css");
setLanguage("Stylus", "stylus", "css"); // not PhpStorm
setLanguage("HAML", "haml");
setLanguage("CoffeeScript", "coffee", "javascript", "jquery", "jqueryui", "jquerym", "backbone", "marionette", "meteor", "sproutcore", "moo", "prototype", "bootstrap", "foundation", "lodash", "underscore", "ember", "sencha", "extjs", "titanium", "knockout", "zepto", "yui", "d3", "dojo", "nodejs", "express", "grunt", "mongoose", "moment", "require", "awsjs", "jasmine", "sinon", "chai", "cordova", "phonegap"); // not IntelliJ

setLanguage("JavaScript", (Object[])FileTypeSpecificKeyword.createList(
new String[]{"javascript", "jquery", "jqueryui", "jquerym", "backbone", "marionette", "meteor", "sproutcore", "moo", "prototype", "bootstrap", "foundation", "lodash", "underscore", "ember", "sencha", "extjs", "titanium", "knockout", "zepto", "yui", "d3", "dojo", "nodejs", "express", "grunt", "mongoose", "moment", "require", "awsjs", "jasmine", "sinon", "chai", "cordova", "phonegap", "angularjs", "angularts", "angular"},
"ActionScript", new String[]{"actionscript"})
);

setLanguage("MySQL", "mysql"); // not WebStorm
setLanguage("SQLite", "sqlite"); // not WebStorm

// Products listed for each entry
final IKeyword javaVersionedKeyword = new JavaSdkVersionDependentKeyword("java6", "java7", "java8", "java9");
final IKeyword javaKeyword = new SdkTypeSpecificKeyword("java", "Android SDK", "android");
final IKeyword javaFxKeyword = new ExcludeSdkTypeKeyword("javafx", "Android SDK");
final IKeyword grailsKeyword = new ExcludeSdkTypeKeyword("grails", "Android SDK");
final IKeyword groovyKeyword = new ExcludeSdkTypeKeyword("groovy", "Android SDK");
final IKeyword playjavaKeyword = new ExcludeSdkTypeKeyword("playjava", "Android SDK");
final IKeyword springKeyword = new ExcludeSdkTypeKeyword("spring", "Android SDK");

setLanguage("Dart", "dartlang", "dartdocs", "polymerdart", "angulardart"); // WebStorm
setLanguage("DjangoTemplate", "django"); // PyCharm
setLanguage("Groovy", "groovy"); // IntelliJ
setLanguage("Jade", "jade"); // WebStorm
setLanguage("JAVA", javaVersionedKeyword, javaKeyword, javaFxKeyword, grailsKeyword, groovyKeyword, playjavaKeyword, springKeyword, "cvj", "processing", "javadoc"); // IntelliJ
setLanguage("JsInJade", "javascript", "jade"); // WebStorm
setLanguage("JSP", javaVersionedKeyword, javaKeyword, javaFxKeyword, grailsKeyword, groovyKeyword, playjavaKeyword, springKeyword, "cvj", "javadoc"); // IntelliJ, WebStorm, PhpStorm
setLanguage("JSPX", javaVersionedKeyword, javaKeyword, javaFxKeyword, grailsKeyword, groovyKeyword, playjavaKeyword, springKeyword, "cvj", "javadoc"); // IntelliJ, WebStorm, PhpStorm
setLanguage("Mxml", "actionscript"); // IntelliJ
setLanguage("PHP", "php", "wordpress", "drupal", "zend", "laravel", "yii", "joomla", "ee", "codeigniter", "cakephp", "phpunit", "symfony", "typo3", "twig", "smarty", "phpp"); // PhpStorm
setLanguage("Play", "playjava"); // IntelliJ; uncertain
setLanguage("Puppet", "puppet"); // RubyMine, PyCharm
setLanguage("Python", new PythonSdkVersionDependentKeyword("python2", "python3"), "python", "django", "twisted", "sphinx", "flask", "tornado", "sqlalchemy", "numpy", "scipy", "salt", "cvp", "matplotlib"); // PyCharm
setLanguage("ruby", "ruby", "rubygems", "rails"); // RubyMine
setLanguage("Smarty", "smarty"); // PhpStorm
setLanguage("SmartyConfig", "smarty"); // PhpStorm
setLanguage("Twig", "twig"); // PhpStorm
setLanguage("go", "go", "godoc"); // GoLand

// SQL
setLanguage("SQL", new SqlDialectDependentKeyword("mysql", "mysql", "sqlite", "psql"));
setLanguage("PostgreSQL", "psql");

// Jetbrains Plugins
setLanguage("Haskell", "haskell");
setLanguage("Scala", "scala", "akka", "playscala");
setLanguage("SSP", "scala", "akka", "playscala");
setLanguage("TypoScript", "typo3");
setLanguage("Dockerfile", "docker", "bash", "manpages");

// Third-party Plugins
setLanguage("Bash", "bash", "manpages");
setLanguage("Google Go", "go", "godoc");
setLanguage("Lua", "lua", "corona");
setLanguage("Markdown", "markdown");
setLanguage("Clojure", "clojure");
setLanguage("Erlang", "erlang");
setLanguage("Elixir", "elixir");


/*
use the following command to display all available languages in the event log. intended for development purposes.
listRegisteredLanguages();
*/
}


private void listRegisteredLanguages() {
Collection<Language> languages = Language.getRegisteredLanguages();

ArrayList<String> languageList = new ArrayList<String>();

for ( Language language : languages ) {
String languageStr = language.getID();

Language baseLanguage = language.getBaseLanguage();
while ( baseLanguage != null ) {
languageStr += " <- " + baseLanguage.getID();
baseLanguage = baseLanguage.getBaseLanguage();
}

languageList.add(languageStr);
}

Collections.sort(languageList);

String message = "";
for ( String s : languageList ) {
message += s + "\n";
}

Notifications.Bus.notify(new Notification("Dash", "Dash: Registered Languages ", message, NotificationType.INFORMATION));
}

private void setLanguage(String language, Object... keywords)
{
ArrayList<IKeyword> keywordList = new ArrayList<IKeyword>();

for (Object keyword : keywords) {
if ( keyword instanceof String ) {
keywordList.add(new Keyword((String) keyword));
}
else if ( keyword instanceof IKeyword ) {
keywordList.add((IKeyword) keyword);
}
else {
throw new Error("Invalid keyword");
}

}

languageMap.put(language, keywordList);
}

public String findLanguageName(Language language)
{
while ( language != null ) {
if ( languageMap.containsKey(language.getID()) ) {
return language.getID();
}

language = language.getBaseLanguage();
}

return null;
}

public List<String> findKeywords(final LookupInfoDictionary dict)
{
ArrayList<String> result = new ArrayList<String>();

String languageName = findLanguageName(dict.getLanguage());
if ( languageName != null ) {
for ( IKeyword keyword : languageMap.get(languageName) ) {
String name = keyword.getName(dict);

if ( name != null ) {
result.add(name);
}
}
}

return result;
}
}
98 changes: 98 additions & 0 deletions src/de/dreamlab/dash/LookupInfoDictionary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package de.dreamlab.dash;

import com.intellij.lang.Language;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;

public class LookupInfoDictionary{
private Language language;
private PsiElement psiElement;
private Project project;
private PsiFile psiFile;
private VirtualFile virtualFile;

private boolean isSdk = false;
private Sdk sdk = null;

private boolean isFileSqlLanguage = false;
private Language fileSqlLanguage;


public LookupInfoDictionary(Language language, PsiElement psiElement, Project project, PsiFile psiFile, VirtualFile virtualFile) {
this.language = language;
this.psiElement = psiElement;
this.project = project;
this.psiFile = psiFile;
this.virtualFile = virtualFile;
}

// initially set values
public Language getLanguage() {
return language;
}

public PsiElement getPsiElement() {
return psiElement;
}

public Project getProject() {
return project;
}

public PsiFile getPsiFile() {
return psiFile;
}

public VirtualFile getVirtualFile() {
return virtualFile;
}

// optional sdk value
public boolean isSdk() {
return isSdk;
}

public Sdk getSdk() {
if ( !isSdk) {
throw new Error("sdk has not been set");
}

return sdk;
}

public void setSdk(Sdk sdk) {
if (isSdk) {
throw new Error("sdk can only be set once");
}

this.sdk = sdk;
this.isSdk = true;
}

// optional fileSqlLanguage value
public boolean isFileSqlLanguage() {
return isFileSqlLanguage;
}

public Language getFileSqlLanguage() {
if ( !isFileSqlLanguage) {
throw new Error("fileSqlLanguage has not been set");
}

return fileSqlLanguage;
}

public void setFileSqlLanguage(Language fileSqlLanguage) {
if (isFileSqlLanguage) {
throw new Error("fileSqlLanguage can only be set once");
}

this.fileSqlLanguage = fileSqlLanguage;
this.isFileSqlLanguage = true;
}


}
27 changes: 27 additions & 0 deletions src/de/dreamlab/dash/SearchAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.dreamlab.dash;

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;


public class SearchAction extends AbstractMenuAction {
public SearchAction()
{
title = "Search all Documentation";
description = "Searches word under caret or selection in documentation";
}

public void actionPerformed(AnActionEvent e) {
final Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext());
if ( editor == null ) {
return;
}

final Project project = e.getProject();
final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);

SearchService.getInstance().search(editor, project, psiFile);
}
}
217 changes: 217 additions & 0 deletions src/de/dreamlab/dash/SearchService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package de.dreamlab.dash;

import com.intellij.lang.Language;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.impl.status.StatusBarUtil;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import de.dreamlab.dash.launcher.AbstractLauncher;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;

public class SearchService {
// singleton
private static SearchService ourInstance = new SearchService();

public static SearchService getInstance()
{
return ourInstance;
}

// class instance
private static final String XML_LANGUAGE_ID = "XML";
private KeywordLookup keywordLookup;
private AbstractLauncher launcher;


private SearchService() {
keywordLookup = new KeywordLookup();
launcher = AbstractLauncher.createInstance();
}

private @Nullable PsiElement getPsiElementAtCursor(@Nonnull Editor editor, @Nullable Project project, @Nullable PsiFile psiFile)
{
if ( psiFile == null ) {
return null;
}

int caretOffset = editor.getCaretModel().getOffset();

if ( project != null ) {
InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(project);

if ( injectedLanguageManager != null ) {
PsiElement injectedPsiElement = injectedLanguageManager.findInjectedElementAt(psiFile, caretOffset);

if ( injectedPsiElement != null ) {
return injectedPsiElement;
}
}
}

return psiFile.findElementAt(editor.getCaretModel().getOffset());
}

private @Nullable String getSearchQueryFromEditor(@Nonnull Editor editor, @Nullable PsiElement psiElement)
{
SelectionModel selectionModel = editor.getSelectionModel();
if ( selectionModel.hasSelection() ) {
return selectionModel.getSelectedText();
}

if ( psiElement == null || psiElement instanceof PsiComment ) {
return getWordAtCursor(editor);
}

return psiElement.getText();
}

public void search(@Nonnull Editor editor, @Nullable Project project, @Nullable PsiFile psiFile)
{
PsiElement psiElement = getPsiElementAtCursor(editor, project, psiFile);
String query = getSearchQueryFromEditor(editor, psiElement);

if ( query == null ) {
return;
}

// open dash
showStatusMessage(project, null, null);
launcher.search(new ArrayList<>(), query);
}

public void smartSearch(@Nonnull Editor editor, @Nullable Project project, @Nullable PsiFile psiFile, @Nullable VirtualFile virtualFile)
{
PsiElement psiElement = getPsiElementAtCursor(editor, project, psiFile);
Language language = elementLanguage(psiElement);
String resolvedLanguage = keywordLookup.findLanguageName(language);

if ( resolvedLanguage == null ) {
psiElement = null;
}

String query = getSearchQueryFromEditor(editor, psiElement);

if ( query == null ) {
return;
}

// open dash
showStatusMessage(project, resolvedLanguage, language);
launcher.search(keywordLookup.findKeywords(new LookupInfoDictionary(language, psiElement, project, psiFile, virtualFile)), query);

/*
use the following command to display information about the sdk in use in the event log. intended for development purposes.
showSdkDebug(AbstractSdkKeyword.findSdk(psiElement, project, psiFile, virtualFile));
*/
}

private void showStatusMessage(final @Nullable Project project, final @Nullable String resolvedLanguage, final @Nullable Language language)
{
if ( project == null ) {
return;
}

// show status message for potential troubleshooting
final StringBuilder messageBuilder = new StringBuilder();

if ( resolvedLanguage == null ) {
messageBuilder.append("Searching all documentation");
}
else {
messageBuilder.append(String.format("Smart-Searching \"%s\" documentation", resolvedLanguage));
}

if ( language != null && !language.getID().equals(resolvedLanguage) ) {
messageBuilder.append(String.format(". Based on \"%s\" context.", language.getID()));
}

StatusBarUtil.setStatusBarInfo(project, messageBuilder.toString());
}

private void showSdkDebug(@Nullable Sdk sdk)
{
StringBuilder sdkMessage = new StringBuilder();

if ( sdk != null ) {
sdkMessage.append(String.format("Name: %s\n", sdk.getName()));
sdkMessage.append(String.format("SdkType: %s\n", sdk.getSdkType().getName()));
sdkMessage.append(String.format("VersionString: %s\n", sdk.getVersionString()));

}
else {
sdkMessage.append("not available");
}

Notifications.Bus.notify(new Notification("Dash", "Dash SDK: ", sdkMessage.toString(), NotificationType.INFORMATION));
}

private @Nullable Language elementLanguage(final @Nullable PsiElement element)
{
if ( element == null ) {
return null;
}

try {
if ( XML_LANGUAGE_ID.equals(element.getLanguage().getID()) ) {
PsiElement parent = element.getParent();

if ( !XML_LANGUAGE_ID.equals(parent.getLanguage().getID()) && XML_LANGUAGE_ID.equals(parent.getLanguage().getBaseLanguage().getID()) ) {
return parent.getLanguage();
}
}

return element.getLanguage();
}
catch ( NullPointerException e ) {
return null;
}
}

private @Nullable String getWordAtCursor(final @Nonnull Editor editor)
{
CharSequence editorText = editor.getDocument().getCharsSequence();
int cursorOffset = editor.getCaretModel().getOffset();
int editorTextLength = editorText.length();

if ( editorTextLength == 0 ) {
return null;
}

if ( (cursorOffset >= editorTextLength) || (cursorOffset > 1 && !isIdentifierPart(editorText.charAt(cursorOffset) ) && isIdentifierPart(editorText.charAt(cursorOffset - 1))) ) {
cursorOffset--;
}

if ( isIdentifierPart(editorText.charAt(cursorOffset)) ) {
int start = cursorOffset;
int end = cursorOffset;

while ( start > 0 && isIdentifierPart(editorText.charAt(start-1)) ) {
start--;
}

while ( end < editorTextLength && isIdentifierPart(editorText.charAt(end)) ) {
end++;
}

return editorText.subSequence(start, end).toString();
}
return null;
}

private boolean isIdentifierPart(final char ch)
{
return Character.isJavaIdentifierPart(ch);
}
}
33 changes: 33 additions & 0 deletions src/de/dreamlab/dash/SmartSearchAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.dreamlab.dash;


import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;

public class SmartSearchAction extends AbstractMenuAction {

public SmartSearchAction()
{
title = "Smart-Search Documentation";
description = "Searches word under caret or selection in documentation filtered by currently used language";
iconFilename = "dash.png";
}

public void actionPerformed(AnActionEvent e) {
final Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext());
if ( editor == null ) {
return;
}

final Project project = e.getProject();
final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
final VirtualFile virtualFile = e.getData(LangDataKeys.VIRTUAL_FILE);

SearchService.getInstance().smartSearch(editor, project, psiFile, virtualFile);
}
}
35 changes: 35 additions & 0 deletions src/de/dreamlab/dash/SystemUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.dreamlab.dash;

public class SystemUtil {
private static boolean isOSMac = false;
private static boolean isOSWindows = false;
private static boolean isOSLinux = false;

static {
try {
String osName = System.getProperty("os.name").toLowerCase();

if ( osName.startsWith("mac") ) {
isOSMac = true;
} else if ( osName.startsWith("windows") ) {
isOSWindows = true;
} else if ( osName.startsWith("linux") ) {
isOSLinux = true;
}
}
catch ( Throwable e ) {
}
}

public static boolean isIsOSMac() {
return isOSMac;
}

public static boolean isIsOSWindows() {
return isOSWindows;
}

public static boolean isIsOSLinux() {
return isOSLinux;
}
}
56 changes: 56 additions & 0 deletions src/de/dreamlab/dash/keywords/AbstractSdkKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package de.dreamlab.dash.keywords;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import de.dreamlab.dash.LookupInfoDictionary;

public abstract class AbstractSdkKeyword {

protected Sdk getSdk(LookupInfoDictionary dict)
{
if ( !dict.isSdk() ) {
dict.setSdk(findSdk(dict.getPsiElement(), dict.getProject(), dict.getPsiFile(), dict.getVirtualFile()));
}

return dict.getSdk();
}

public static Sdk findSdk(final PsiElement psiElement, final Project project, final PsiFile psiFile, final VirtualFile virtualFile)
{
Module module = null;

if ( psiFile != null ) {
module = ModuleUtil.findModuleForPsiElement(psiFile);

// Get the module associated with the PsiElement, if one is present.
if (module == null && psiElement != null) {
module = ModuleUtil.findModuleForPsiElement(psiElement);
}
}

// Get the module associated with the VIRTUAL_FILE, if one is present.
if ( module == null ) {
if ( virtualFile != null && project != null ) {
module = ModuleUtil.findModuleForFile(virtualFile, project);
}
}

// Get the SDK associated with the previously found module, or use the project-wide SDK if no module has been found.
if ( module != null ) {
return ModuleRootManager.getInstance(module).getSdk();
}
else if ( project != null) {
return ProjectRootManager.getInstance(project).getProjectSdk();
}
else {
return null;
}
}
}
28 changes: 28 additions & 0 deletions src/de/dreamlab/dash/keywords/ExcludeFileTypeKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.dreamlab.dash.keywords;

import de.dreamlab.dash.LookupInfoDictionary;

public class ExcludeFileTypeKeyword implements IKeyword {
private String keyword;
private String fileType;


public ExcludeFileTypeKeyword(String keyword, String fileType)
{
this.keyword = keyword;
this.fileType = fileType;
}

@Override
public String getName(LookupInfoDictionary dict) {
try {
if (fileType.equals(dict.getPsiFile().getFileType().getName())) {
return null;
}
}
catch ( Throwable e ) {
}

return keyword;
}
}
28 changes: 28 additions & 0 deletions src/de/dreamlab/dash/keywords/ExcludeSdkTypeKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.dreamlab.dash.keywords;

import com.intellij.openapi.projectRoots.Sdk;
import de.dreamlab.dash.LookupInfoDictionary;

public class ExcludeSdkTypeKeyword extends AbstractSdkKeyword implements IKeyword {
private String keyword;
private String sdkType;

public ExcludeSdkTypeKeyword(String keyword, String sdkType) {
this.keyword = keyword;
this.sdkType = sdkType;
}

public String getName(final LookupInfoDictionary dict) {
Sdk sdk = getSdk(dict);

if ( sdkType == null ) {
return null;
}
else if ( sdk != null && !sdkType.equals(sdk.getSdkType().getName()) ) {
return keyword;
}
else {
return null;
}
}
}
43 changes: 43 additions & 0 deletions src/de/dreamlab/dash/keywords/FileTypeSpecificKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.dreamlab.dash.keywords;

import de.dreamlab.dash.LookupInfoDictionary;

import java.util.ArrayList;

public class FileTypeSpecificKeyword implements IKeyword {
private String keyword;
private String fileType;


public FileTypeSpecificKeyword(String keyword, String fileType) {
this.keyword = keyword;
this.fileType = fileType;
}

@Override
public String getName(LookupInfoDictionary dict) {
try {
if (fileType.equals(dict.getPsiFile().getFileType().getName())) {
return keyword;
}
} catch (Throwable e) {
}

return null;
}

public static IKeyword[] createList(String[] defaultKeywords, String fileType, String[] fileTypeSpecificKeywords)
{
ArrayList<IKeyword> result = new ArrayList<IKeyword>();

for ( String defaultKeyword : defaultKeywords ) {
result.add(new ExcludeFileTypeKeyword(defaultKeyword, fileType));
}

for ( String fileTypeSpecificKeyword : fileTypeSpecificKeywords ) {
result.add(new FileTypeSpecificKeyword(fileTypeSpecificKeyword, fileType));
}

return result.toArray(new IKeyword[result.size()]);
}
}
9 changes: 9 additions & 0 deletions src/de/dreamlab/dash/keywords/IKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.dreamlab.dash.keywords;

import com.sun.istack.internal.Nullable;
import de.dreamlab.dash.LookupInfoDictionary;

public interface IKeyword {
@Nullable
public String getName(final LookupInfoDictionary dict);
}
44 changes: 44 additions & 0 deletions src/de/dreamlab/dash/keywords/JavaSdkVersionDependentKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.dreamlab.dash.keywords;

import com.intellij.openapi.projectRoots.Sdk;
import de.dreamlab.dash.LookupInfoDictionary;

public class JavaSdkVersionDependentKeyword extends AbstractSdkKeyword implements IKeyword {
private String java6Keyword;
private String java7Keyword;
private String java8Keyword;
private String java9Keyword;

public JavaSdkVersionDependentKeyword(String java6Keyword, String java7Keyword, String java8Keyword, String java9Keyword) {
this.java6Keyword = java6Keyword;
this.java7Keyword = java7Keyword;
this.java8Keyword = java8Keyword;
this.java9Keyword = java9Keyword;
}

@Override
public String getName(LookupInfoDictionary dict) {
Sdk sdk = getSdk(dict);

if ( sdk != null && sdk.getSdkType().getName().equals("JavaSDK") ) {
String versionString = sdk.getVersionString();

if ( versionString != null ) {
if ( versionString.contains("1.6.") ) {
return java6Keyword;
}
else if ( versionString.contains("1.7.") ) {
return java7Keyword;
}
else if ( versionString.contains("1.8.") ) {
return java8Keyword;
}
else if ( versionString.contains("1.9.") ) {
return java9Keyword;
}
}
}

return null;
}
}
15 changes: 15 additions & 0 deletions src/de/dreamlab/dash/keywords/Keyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.dreamlab.dash.keywords;

import de.dreamlab.dash.LookupInfoDictionary;

public class Keyword implements IKeyword {
private String keyword;

public Keyword(String keyword) {
this.keyword = keyword;
}

public String getName(final LookupInfoDictionary dict) {
return keyword;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package de.dreamlab.dash.keywords;

import com.intellij.openapi.projectRoots.Sdk;
import de.dreamlab.dash.LookupInfoDictionary;

public class PythonSdkVersionDependentKeyword extends AbstractSdkKeyword implements IKeyword {
private String python2Keyword;
private String python3Keyword;

public PythonSdkVersionDependentKeyword(String python2Keyword, String python3Keyword) {
this.python2Keyword = python2Keyword;
this.python3Keyword = python3Keyword;
}

@Override
public String getName(LookupInfoDictionary dict) {
Sdk sdk = getSdk(dict);

if ( sdk != null && sdk.getSdkType().getName().equals("Python SDK") ) {
String versionString = sdk.getVersionString();

if ( versionString != null ) {
if ( versionString.contains("Python 2") ) {
return python2Keyword;
}
else if ( versionString.contains("Python 3") ) {
return python3Keyword;
}
}
}

return null;
}
}
42 changes: 42 additions & 0 deletions src/de/dreamlab/dash/keywords/SdkTypeSpecificKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.dreamlab.dash.keywords;

import com.intellij.openapi.projectRoots.Sdk;
import de.dreamlab.dash.LookupInfoDictionary;

import java.util.HashMap;


public class SdkTypeSpecificKeyword extends AbstractSdkKeyword implements IKeyword {
private String defaultKeyword = null;
private HashMap<String, String> sdkTypes;

public SdkTypeSpecificKeyword(String defaultKeyword, String... sdkTypesAndKeywords) {
if ( (sdkTypesAndKeywords.length % 2) != 0 ) {
throw new Error("Missing keyword for sdk: " + sdkTypesAndKeywords[sdkTypesAndKeywords.length - 1]);
}

this.defaultKeyword = defaultKeyword;

sdkTypes = new HashMap<String, String>();

for ( int i = 0; i < sdkTypesAndKeywords.length; i += 2 ) {
sdkTypes.put(sdkTypesAndKeywords[0], sdkTypesAndKeywords[1]);
}
}

public SdkTypeSpecificKeyword(String keyword, String sdkType) {
sdkTypes = new HashMap<String, String>();
sdkTypes.put(sdkType, keyword);
}

public String getName(final LookupInfoDictionary dict)
{
Sdk sdk = getSdk(dict);

if ( sdk != null && sdkTypes.containsKey(sdk.getSdkType().getName()) ) {
return sdkTypes.get(sdk.getSdkType().getName());
}

return defaultKeyword;
}
}
69 changes: 69 additions & 0 deletions src/de/dreamlab/dash/keywords/SqlDialectDependentKeyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package de.dreamlab.dash.keywords;

import com.intellij.lang.Language;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import de.dreamlab.dash.LookupInfoDictionary;

import java.lang.reflect.Method;
import java.util.HashMap;

public class SqlDialectDependentKeyword implements IKeyword {
private HashMap<String, String> languageMap;

public SqlDialectDependentKeyword(String defaultKeyword, String mySqlKeyword, String sqliteKeyword, String postgreSqlKeyword) {
languageMap = new HashMap<String, String>();

languageMap.put("SQL", defaultKeyword);
languageMap.put("MySQL", mySqlKeyword);
languageMap.put("SQLite", sqliteKeyword);
languageMap.put("PostgreSQL", postgreSqlKeyword);
}

@Override
public String getName(final LookupInfoDictionary dict) {
if ( !dict.isFileSqlLanguage() ) {
setDictFileSqlLanguage(dict);
}

Language fileSqlLanguage = dict.getFileSqlLanguage();

if ( fileSqlLanguage != null ) {
return languageMap.get(findLanguageName(fileSqlLanguage));
}
else {
return null;
}
}

public String findLanguageName(Language language)
{
while ( language != null ) {
if ( languageMap.containsKey(language.getID()) ) {
return language.getID();
}

language = language.getBaseLanguage();
}

return null;
}

private void setDictFileSqlLanguage(LookupInfoDictionary dict)
{
Language language = null;

try {
// using reflection for the following command, because of optional dependencies
// language = com.intellij.sql.dialects.SqlDialectMappings.getMapping(dict.getProject(), dict.getVirtualFile());
Class sqlClass = Class.forName("com.intellij.sql.dialects.SqlDialectMappings");
Method getMappingMethod = sqlClass.getMethod("getMapping", Project.class, VirtualFile.class);
language = (Language)getMappingMethod.invoke(null, dict.getProject(), dict.getVirtualFile());
}
catch (Throwable e) {
}

dict.setFileSqlLanguage(language);
}

}
51 changes: 51 additions & 0 deletions src/de/dreamlab/dash/launcher/AbstractLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package de.dreamlab.dash.launcher;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import de.dreamlab.dash.SystemUtil;

import javax.annotation.Nonnull;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

public abstract class AbstractLauncher {

public static AbstractLauncher createInstance()
{
if ( SystemUtil.isIsOSMac() ) {
return new DashLauncher();
}
else {
return new DashPluginSchemeLauncher();
}
}

abstract protected void openUri(String uriStr) throws Exception;

public void search(final @Nonnull List<String> keywords, final @Nonnull String query)
{
try {
String request = "dash-plugin://";

// keywords
if ( keywords.size() > 0 ) {
request += "keys=" + String.join(",", keywords) + "&";
}

// query
request += "query=" + urlEncode(query);

openUri(request);
}
catch ( Throwable e ) {
Notifications.Bus.notify(new Notification("Dash Plugin Error", "Dash Plugin Error", e.getMessage(), NotificationType.ERROR));
}
}

private String urlEncode(final @Nonnull String s) throws UnsupportedEncodingException
{
return URLEncoder.encode(s, "UTF-8").replace("+", "%20");
}
}
21 changes: 21 additions & 0 deletions src/de/dreamlab/dash/launcher/DashLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Created by gerard on 12.04.15.
*/

package de.dreamlab.dash.launcher;

import com.intellij.execution.configurations.GeneralCommandLine;

import javax.annotation.Nonnull;

public class DashLauncher extends AbstractLauncher {

protected void openUri(final @Nonnull String uriStr) throws Exception
{
final GeneralCommandLine commandLine = new GeneralCommandLine("open");
commandLine.addParameter("-g");
commandLine.addParameter(uriStr);
commandLine.createProcess();
}

}
20 changes: 20 additions & 0 deletions src/de/dreamlab/dash/launcher/DashPluginSchemeLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Created by gerard on 04.04.14.
*/

package de.dreamlab.dash.launcher;

import javax.annotation.Nonnull;
import java.awt.*;
import java.net.URI;

public class DashPluginSchemeLauncher extends AbstractLauncher {

protected void openUri(final @Nonnull String uriStr) throws Exception
{
Desktop desktop = Desktop.getDesktop();
URI uri = new URI(uriStr);
desktop.browse(uri);
}

}