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

Hurricup/bugfixes #2899

Merged
merged 6 commits into from
Sep 8, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gradle/
.kotlin/
.sandbox*
build/
out/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.perl5.lang.perl.extensions.mojo

import com.perl5.lang.perl.psi.references.PerlImplicitDeclarationsProvider
import org.jetbrains.annotations.NonNls

class MojoLiteImplicitSubsProvider : PerlImplicitDeclarationsProvider() {
override fun getDataFileName(): @NonNls String? = "perlData/MojoliciousLite.xml"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.perl5.lang.perl.extensions.mojo;

import com.perl5.lang.perl.extensions.packageprocessor.PerlFeaturesProvider;
import com.perl5.lang.perl.extensions.packageprocessor.PerlPackageParentsProvider;
import com.perl5.lang.perl.extensions.packageprocessor.PerlUtfProvider;
import com.perl5.lang.perl.extensions.packageprocessor.impl.BaseStrictWarningsProvidingProcessor;
import com.perl5.lang.perl.internals.PerlFeaturesTable;
import com.perl5.lang.perl.psi.impl.PerlUseStatementElement;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class MojoliciousLitePackageProcessor extends BaseStrictWarningsProvidingProcessor implements
PerlUtfProvider,
PerlFeaturesProvider,
PerlPackageParentsProvider {
public static final String MOJOLICIOUS_LITE = "Mojolicious::Lite";
private static final List<String> AUTOEXPORTED_SUBS = Arrays.asList(
"app", "new",
"group",
"helper", "hook", "plugin",
"under", "del",
"any", "get", "options", "patch", "post", "put", "websocket"
);

@Override
public int getVersion() {
return super.getVersion() + 1;
}

@Override
public void changeParentsList(@NotNull PerlUseStatementElement useStatement, @NotNull List<? super String> currentList) {
currentList.add(MOJOLICIOUS_LITE);
}

@Override
public void addExports(@NotNull PerlUseStatementElement useStatement,
@NotNull Set<? super String> export,
@NotNull Set<? super String> exportOk) {
export.addAll(AUTOEXPORTED_SUBS);
}

@Override
public PerlFeaturesTable getFeaturesTable(PerlUseStatementElement useStatement, PerlFeaturesTable currentFeaturesTable) {
return currentFeaturesTable.clone();
}

@Override
public boolean hasPackageFilesOptions() {
return false;
}
}
103 changes: 103 additions & 0 deletions mojo/core/src/main/resources/perlData/MojoliciousLite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!--
~ Copyright 2015-2018 Alexandr Evstigneev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<xml>
<package name="Mojolicious::Lite">
<!-- return pre-cooked $app returns="" -->
<sub name="new" returns="Mojolicious::Lite"/>
<sub name="app" returns="Mojolicious::Lite"/>

<!-- executes the code preserving context -->
<sub name="group">
<arguments>
<argument name="route_group" type="&amp;"/>
</arguments>
</sub>

<!-- delegated to $app -->
<sub name="helper" returns="Mojolicious::Renderer">
<arguments>
<argument name="name" type="$"/>
<argument name="handler" type="&amp;"/>
</arguments>
</sub>
<sub name="hook">
<arguments>
<argument name="name" type="$"/>
<argument name="handler" type="&amp;"/>
</arguments>
</sub>
<sub name="plugin">
<arguments>
<argument name="name" type="$"/>
<optional>
<argument name="plugin_args" type="@"/>
</optional>
</arguments>
</sub>

<!-- delegated to $root->under() -->
<sub name="under" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>

<!-- delegated to $routes->delete() -->
<sub name="del" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>

<!-- delegated to $routes -->
<sub name="any" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>
<sub name="get" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>
<sub name="options" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>
<sub name="patch" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>
<sub name="post" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>
<sub name="put" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>
<sub name="websocket" returns="Mojolicious::Routes::Route">
<arguments>
<argument name="route_spec" type="@"/>
</arguments>
</sub>
</package>
</xml>
4 changes: 4 additions & 0 deletions mojo/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

<importsProvider implementation="com.perl5.lang.mojolicious.extensions.MojoImplicitImportsProvider"/>
<settings.configurable.extension implementation="com.perl5.lang.mojolicious.idea.modules.MojoSettingsConfigurableExtension"/>
<packageProcessor key="Mojo::Base" implementationClass="com.perl5.lang.perl.extensions.mojo.MojoBaseProcessor"/>
<packageProcessor key="Mojolicious::Lite" implementationClass="com.perl5.lang.perl.extensions.mojo.MojoliciousLitePackageProcessor"/>

<implicitSubsProvider implementation="com.perl5.lang.perl.extensions.mojo.MojoLiteImplicitSubsProvider"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
Expand Down
32 changes: 30 additions & 2 deletions mojo/src/test/java/completion/MojoPerlCompletionTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,9 +19,12 @@

import base.MojoLightTestCase;
import com.perl5.lang.perl.fileTypes.PerlFileTypeScript;
import com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings;
import com.perl5.lang.perl.idea.project.PerlNamesCache;
import org.junit.Test;

import static com.perl5.lang.perl.extensions.mojo.MojoliciousLitePackageProcessor.MOJOLICIOUS_LITE;

public class MojoPerlCompletionTest extends MojoLightTestCase {
@Override
protected void setUp() throws Exception {
Expand All @@ -34,13 +37,38 @@ protected String getBaseDataPath() {
return "completion/perl";
}


@Override
public String getFileExtension() {
return PerlFileTypeScript.EXTENSION_PL;
}


@Test
public void testMojoLite() {
doTestCompletion(withType(MOJOLICIOUS_LITE));
}

@Test
public void testMojoAttrs() { doTestCompletion(); }

@Test
public void testMainCompletionAll() {
doTestMainCompletion(false);
}

@Test
public void testMainCompletionSimple() {
doTestMainCompletion(true);
}

private void doTestMainCompletion(boolean value) {
PerlSharedSettings.getInstance(getProject()).SIMPLE_MAIN_RESOLUTION = value;
myFixture.copyFileToProject("second_app.pl");
initWithTextSmartWithoutErrors("use Mojolicious::Lite;\n" +
"<caret>");
doTestCompletionCheck("", withType(MOJOLICIOUS_LITE));
}

@Test
public void testMojoliciousHelper() {
doTestCompletion();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,4 +34,11 @@ public String getFileExtension() {

@Test
public void testMojoHelpers() {doTestLightElements();}

@Test
public void testMojoliciousLite() {
withMojo();
doTestLightElements();
}

}
5 changes: 4 additions & 1 deletion mojo/src/test/java/resolve/MojoPerlResolveTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,9 @@ public void testMojoHelperNamespace() {
doTest();
}

@Test
public void testMojoLite() { doTest(); }

private void doTest() {
doTestResolve();
}
Expand Down
Loading
Loading