Code Monkey home page Code Monkey logo

pycharm-pyxl's Introduction

Pyxl Extensions for PyCharm

This PyCharm plugin aims to provide extensions to PyCharm for working with Pyxl files.

Written by Nils Bunger, Robert Kajic and Christoffer Klang.

Installation

Download the plugin jar and switch over to PyCharm > Settings > Plugins > Install plugin from disk... and select the Jar.

Release 1.1

  • Performance fixes
  • Add proper support for language level Python syntax (with as:, etc).
  • Fix xml namespaced attributes
  • Add support for <!DOCTYPE> and <![CDATA[ data data ]]>

Release 1.2

  • PyCharm 2016.1 support

Development

1. Set up plugin development environment

Follow helful guide from Jetbrains

2. Git clone this repo.

3. Generate lexer file using provided JFlex (provided in repo root):

$ java -jar JFlex.jar --skel idea-flex.skeleton --charat src/com/christofferklang/pyxl/parsing/Pyxl.flex

4. Add Python plugin dependency

First install the Python plugin in IntelliJ (Settings > Plugins). Then locate python.jar in your home directory. The exact location will vary depending on OS and IntelliJ version. For Idea 2016.2 on Linux for example, the file can be found in $HOME/.IntelliJIdea2016.2/config/plugins/python/lib. On OSX it would be in ``$HOME/Library/Application Support/IntelliJIdea2016.2/python/lib. You'll probably figure it out by running find . -name 'python.jar' | grep python/lib` in your home directory.

Once located, you need to add the jar file as a dependency to the project. File > Project Structure... > Modules > pycharm-pyxl > Dependencies (Click the green + to add a new dependency) > JARs or directories` (locate python.jar).

Make sure the Python JAR is above <Module source>, and that the scope is set to "Provided".

5. Open this project in IDEA

Then right-click on pycharm-pyxl project and choose "Prepare plugin module for development" at the bottom of context menu. This will generate new jar in the project root which you can add to your PyCharm.

6. Pro-tip - you can launch PyCharm in debug mode to actually debug the plugin.

pycharm-pyxl's People

Contributors

ashtuchkin avatar christoffer avatar christoffer-dropbox avatar kajic avatar nilsbunger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pycharm-pyxl's Issues

NoSuchMethodError when opening any pyxl file in PyCharm 2016.1

com.jetbrains.python.psi.PyImportElement.getElementNamed(Ljava/lang/String;)Lcom/intellij/psi/PsiElement; java.lang.NoSuchMethodError: com.jetbrains.python.psi.PyImportElement.getElementNamed(Ljava/lang/String;)Lcom/intellij/psi/PsiElement; at com.christofferklang.pyxl.psi.PythonClassReference.getImportedPyxlHtmlModuleElement(PythonClassReference.java:226) at com.christofferklang.pyxl.psi.PythonClassReference.getQualifier(PythonClassReference.java:154) at com.jetbrains.python.codeInsight.PyInjectionUtil.a(PyInjectionUtil.java:126) at com.jetbrains.python.codeInsight.PyInjectionUtil.a(PyInjectionUtil.java:111) at com.jetbrains.python.codeInsight.PyInjectionUtil.getLargestStringLiteral(PyInjectionUtil.java:75) at com.jetbrains.python.codeInsight.regexp.PythonRegexpInjector.getLanguagesToInject(PythonRegexpInjector.java:75) at com.intellij.psi.impl.source.tree.injected.InjectedPsiCachedValueProvider$MyInjProcessor.process(InjectedPsiCachedValueProvider.java:82) at com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl.processInPlaceInjectorsFor(InjectedLanguageManagerImpl.java:474) at com.intellij.psi.impl.source.tree.injected.InjectedPsiCachedValueProvider.doCompute(InjectedPsiCachedValueProvider.java:62) at com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.a(InjectedLanguageUtil.java:316) at com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.enumerate(InjectedLanguageUtil.java:145) at com.intellij.codeInsight.daemon.impl.InjectedGeneralHighlightingPass$2.process(InjectedGeneralHighlightingPass.java:191) at com.intellij.codeInsight.daemon.impl.InjectedGeneralHighlightingPass$2.process(InjectedGeneralHighlightingPass.java:186) at com.intellij.concurrency.ApplierCompleter.a(ApplierCompleter.java:128) at com.intellij.concurrency.ApplierCompleter.access$000(ApplierCompleter.java:44) at com.intellij.concurrency.ApplierCompleter$1.run(ApplierCompleter.java:91) at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1178) at com.intellij.concurrency.ApplierCompleter$2.run(ApplierCompleter.java:100) at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:446) at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:443) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54) at com.intellij.concurrency.ApplierCompleter.a(ApplierCompleter.java:112) at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:88) at jsr166e.CountedCompleter.exec(CountedCompleter.java:684) at jsr166e.ForkJoinTask.doExec(ForkJoinTask.java:260) at jsr166e.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:858) at jsr166e.ForkJoinPool.scan(ForkJoinPool.java:1687) at jsr166e.ForkJoinPool.runWorker(ForkJoinPool.java:1642) at jsr166e.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:108)

False positive causing issues with pure python files

This snippet is an example where the lexer get's a false positive, from matplotlib/axes.py

scaley = (yy<ymin) or (yy>ymax)

This throws an exception on word indexing (for find usages):

Error while indexing /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py
To reindex this file IDEA has to be restarted 
java.lang.RuntimeException: child must not be null: expression text <ymin

print_function from __future__ causes parse error highlight

With a code snippet like this:

from __future__ import print_function
print("hi") 

I get the following error reported by the IDE: "Statement expected, found Py:PRINT_KEYWORD"

When I disable the Pyxl plugin, PyCharm parses the file properly.

IDE errors when typing Pyxl in certain places

  • Open a new document with the plugin activated
  • Enter:
# coding: pyxl

from src.pyxl import html

<div>
  • Cry as the IDE spits out errors over expression children not being able to be null

I'm pretty sure this will be fixed once we get the parser to work as the real pyxl parser, i.e. only interpret pyxl as pyxl in a limited set of places.

Filing a bug anyway since I found a reproducible case to verify against once we get that in place.

Generator expressions support

Currently generator expressions looks to be unsupported:
image

image

But it works fine if we convert it to list:
image

Code in question:

tag = (<ul>
    {render_item(n) for n in items}
</ul>)

PyCharm 2017.2.1

Comments in multiline comments regression

Putting a comment at the end of a multiline attribute list in Pyxl causes the lexer to bork (BAD_CHAR).

I know I fixed this at some point, and there must have been a recent regression. Could you have a quick look at it @nilsbunger ?

<link_button
    importance="secondary" # still broken
    variant="big"
    href="/business/try"
>
    {self.content['button-text']}
</link_button>

PEP 484 Incompatibility

When the Pyxl plugin is installed in PyCharm 2016.3.2, PEP 484 type annotations are not properly recognized. My project interpreter is correctly set to Python 3. I resolved the issue for the time being by uninstalling the Pyxl plugin and restarting with File > Invalidate caches/restart....

PyCharm 2016.3.2
Build #PY-163.10154.50, built on December 28, 2016

Add support of new versions

I have an error with PyCharm Professional 2020.3.1
Any suggestions?

java.lang.NoSuchMethodError: 'boolean com.jetbrains.python.psi.LanguageLevel.hasWithStatement()'
	at com.christofferklang.pyxl.parsing.PyxlHighlightingLexer.getTokenType(PyxlHighlightingLexer.java:56)
	at com.intellij.openapi.editor.ex.util.ValidatingLexerWrapper.getTokenType(ValidatingLexerWrapper.java:50)
	at com.intellij.openapi.editor.ex.util.ValidatingLexerWrapper.advance(ValidatingLexerWrapper.java:87)
	at com.intellij.openapi.editor.ex.util.LexerEditorHighlighter.doSetText(LexerEditorHighlighter.java:453)
	at com.intellij.openapi.editor.ex.util.LexerEditorHighlighter.setText(LexerEditorHighlighter.java:420)
	at com.intellij.openapi.fileEditor.impl.text.TextEditorImpl.loadEditorInBackground(TextEditorImpl.java:74)
	at com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorImpl.loadEditorInBackground(PsiAwareTextEditorImpl.java:42)
	at com.intellij.openapi.fileEditor.impl.text.AsyncEditorLoader.lambda$scheduleLoading$0(AsyncEditorLoader.java:96)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:773)
	at com.intellij.openapi.fileEditor.impl.text.AsyncEditorLoader.lambda$scheduleLoading$1(AsyncEditorLoader.java:94)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:521)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$attemptComputation$3(NonBlockingReadActionImpl.java:468)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1137)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:76)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:152)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$1(ProgressIndicatorUtils.java:113)
	at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:59)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:178)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:658)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:610)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:65)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:165)
	at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:59)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:110)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:76)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.attemptComputation(NonBlockingReadActionImpl.java:486)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$1(NonBlockingReadActionImpl.java:408)
	at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:216)
	at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:27)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.execute(BoundedTaskExecutor.java:195)
	at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:208)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:184)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:834)

Issue with multiline strings for attributes

I'm seeing some other breakage in some files when attributes have multiline strings.

Granted it's really, really ugly, it shouldn't brake the lexer :)

<list_menu
    class="select-input-dropdown
           {'select-input-disable-error' if self.disable_errors else ''}"
    aria-hidden="true" nohover="{True}">
    {children}
</list_menu>

Missing support for <cond_comment>

This is a valid Pyxl tag:

                <cond_comment cond="lt IE 9">
                    <script src="/foo.js"></script>
                </cond_comment>

The Pyxl plugin doesn't handle it properly.

Cannot open file when it has # coding: pyxl not on the first line

When this plugin is installed in PyCharm 2016.1, you cannot open a file that has new line and then pyxl annotation, like this:


# coding: pyxl
... other stuff ..

I started to debug this and found that the problem is with the highlighting lexer - it returns tokens with gaps, specifically it returns "new line" at pos 0-1, then another "new line" at pos 14-15, skipping the coding string. My guess is that the problem is in lexer definition, but I don't have time to fix it for now. Maybe somebody else can do it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.