Giter VIP home page Giter VIP logo

deep-assoc-completion-vscode's Introduction

deep-assoc-completion for vscode

A work-in-progress extension for vscode similar to it's phpstorm counterpart

If you are getting irrelevant global keywords in key completion, you most likely want to untick the PHP > Suggest: Basic in vscode Preferences (php.suggest.basic)

image

Place caret between quotes when typing the associative array key and hit Ctrl+Space to get completions

Supposedly will achieve this: bmewburn/vscode-intelephense#249

Uses vscode-intelephense for php syntax tree traversal.

List of features implemented so far: (yet to be updated)

  • Specify associative array keys in phpdoc for completion and type inference with PSALM format.
  • Infer array key types
  • Infer function call result types
  • ...

vscode repo page: https://marketplace.visualstudio.com/items?itemName=klesun.deep-assoc-completion-vscode

Steps to run

  • git clone this project
  • run npm ci (if you forget to do that you'll get The terminal process terminated with exit code: 1 error)
  • open this project root in vscode
  • hit F5 to run sandbox instance of vscode with this extension plugged in

Misc

Smoke Tests repository: https://github.com/klesun-misc/deep-assoc-lsp-tests


This extension is an order we received on https://klesun-productions.com

Thanks to Louis and Mike for being homies

deep-assoc-completion-vscode's People

Contributors

klesun avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

deep-assoc-completion-vscode's Issues

Feature priority list

@mholubowski please edit or post in a comment a list of the features you want to be implemented first in descending order so I knew what to do first. The list should supposedly include, but not be limited to:

  • Completion based on explicitly created associative arrays returned from a function (done - #4)

  • Support type info from psalm phpdoc annotations (done - #2)

  • Make completion popup appear automatically when you type quotes. (done - klesun/deep-assoc-lang-server@a3c1912)

  • Preserve type info in various language constructs: foreach, $arr[$i]['key'], etc... (estimate: 4 days)

  • Support psalm return type (done - klesun/deep-assoc-lang-server@14f058c)

  • Global files with @psalm-import-type support - PSALM-like type definitions to reuse in doc comments (done)

  • Try to integrate with PSALM language server (cancelled as not needed: completion will not depend on runtime, and for error analysis you should use Psalm (PHP Static Analysis Linting Machine) extension)

  • Try to research how to hide global completions out of the box without manually disabling them in PHP > Basic Completion. Seems to be possible (done in c4b1f5d)

  • Infer type of key assigned to a var like $arr['someKey'] = ... (done in klesun/deep-assoc-lang-server@39fd144)

  • Suppport ternary, elvis and null coalesce operators

  • Infer types from built-in functions like array_keys, array_shift, array_column, etc...

  • GoTo key definition (estimate: 1 day)

  • Type inference in anonymous functions, like in array_map, array_filter, etc... (estimate: 2 days)

  • Function argument key completion (estimate: 1 day)

  • Type completion in psalm docs: int, string, array, classes, aliases, etc...

  • GoTo classes in doc type expressions

  • Support types from @var phpdoc

  • Add intelisense for @psalm-import-type: completion, GoTo, highlight wrong type names

  • Specify function return value as type in phpdoc

Not sure following is needed/prioritized before stuff above is done:

  • Continuous keys resolution and optimization: suggest keys one by one as soon as they are resolved, without waiting for whole structure to be resolved (estimate: 3 days)

  • Key value type preview in completion

  • Private function usage-based argument completion

  • Object field/method completion based on deep-assoc resolution (relevant in anonymous functions mostly)

  • String value completion (for enum-like string values) (done - klesun/deep-assoc-lang-server@2fb11e9)

  • Connected database based row var keys completion

  • Built-in function argument/return keys completion (like stream_context_create(['http' => [...]]))

  • Original deep-assoc = php doc format

Implement basic parser for PSALM type string

Dear @dogzy123, please implement a PsalmTypeExprParser.ts module that would provide a parse() function. parse() should take a single string argument in format:
(see: https://psalm.dev/docs/annotating_code/type_syntax/atomic_types/)

array{
    key1: string,
    key2: int,
    keyzhopa: \Some\Thing<\DateTime>,
    keypizda: array<array{
        keyololo1: float,
        keyololo2: float
    }>
}

and return an object of following structure:

{
    "kind": "TAssoc",
    "keys": {
        "key1": {"kind":"TClass","fqn":"string","generics":[]},
        "key2": {"kind":"TClass","fqn":"int","generics":[]},
        "keyzhopa": {
            "kind": "TClass",
            "fqn": "SomeThing",
            "generics": [{"kind":"TClass","fqn":"DateTime"}]
        },
        "keypizda": {
            "kind": "TClass",
            "fqn": "array",
            "generics": [
                {
                    "kind": "TAssoc",
                    "keys": {
                        "keyololo1": {"kind":"TClass","fqn":"float"},
                        "keyololo2": {"kind":"TClass","fqn":"float"}
                    }
                }
            ]
        }
    }
}

Preferable with typescript.

Please, see the java implementation of same parser here

If you grep for "provide_psalm" in the phpstorm plugin project, you'll find some more useful examples of the PSALM format

P.S. if possible, please cover few examples of input values with mochajs unit tests

Error: Request knownDocuments defines 1 params but recevied none.

The first indexing works fine, but on the second project opening I receive this error: deep-assoc index exc.

Debugging the extension, this is the info about the error:

[2022-04-03 12:49:56.977] [renderer1] [error] [Extension Host] Error: Request knownDocuments defines 1 params but recevied none.
    at handleResponse (/home/barbu/.vscode/extensions/klesun.deep-assoc-completion-vscode-0.9.0/node_modules/vscode-jsonrpc/lib/common/connection.js:477:48)
    at processMessageQueue (/home/barbu/.vscode/extensions/klesun.deep-assoc-completion-vscode-0.9.0/node_modules/vscode-jsonrpc/lib/common/connection.js:292:17)
    at Immediate.<anonymous> (/home/barbu/.vscode/extensions/klesun.deep-assoc-completion-vscode-0.9.0/node_modules/vscode-jsonrpc/lib/common/connection.js:276:13)
    at processImmediate (node:internal/timers:464:21)

It comes froom WorkspaceDiscovery.ts, line 223.. If I disable the knownDocumentsRequest call and timestamp to 0 and cachedUriSet to [], then the extension doesn't throw that error any more.

It seems as if Intelephense's knownDocuments method doesn't receive everything it wants.

Thank you!

Plugin no responding.

After install. I wrote code like

$aa=['a'=>1];

$a = $aa['....

However i got nothing.

I tried to follow the "Steps to run", however what does 'hit F5 to run sandbox instance of vscode' mean? F5 is debug mode right?

Extension throws error if the project contains "tsconfig.json" in the root project folder

Thank you for this extension! It would fill a great need in PHP when using VS Code.

I have an error on projects that have "tsconfig.json" in the root of the project:


.vscode/extensions/klesun.deep-assoc-completion-vscode-0.9.0/node_modules/deep-assoc-lang-server/src/server.ts:1
import { createConnection, ProposedFeatures, TextDocumentSyncKind, RequestType, } from 'vscode-languageserver';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1085:15)
    at Module._compile (node:internal/modules/cjs/loader:1119:27)
    at Module.m._compile (/home/barbu/.vscode/extensions/klesun.deep-assoc-completion-vscode-0.9.0/node_modules/ts-node/dist/index.js:791:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1216:10)
    at Object.require.extensions.<computed> [as .ts] (/home/barbu/.vscode/extensions/klesun.deep-assoc-completion-vscode-0.9.0/node_modules/ts-node/dist/index.js:793:16)
    at Module.load (node:internal/modules/cjs/loader:1035:32)
    at Module._load (node:internal/modules/cjs/loader:876:12)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
    at Module.require (node:internal/modules/cjs/loader:1059:19)
[Info  - 10:31:08 AM] Connection to server got closed. Server will restart.

Thoughts on the possible implementation

The task at hand is to make it possible for a developer to write php code with static typing of associative arrays similar to typescript interfaces.

  • Completion/GoTo
  • Wrong keys error checks
  • Ability to define global type aliases, like @psalm-type

I considered using hack, but that does not seem to be an option anymore in 2k20

First thing to do is to make basic completion from PSALM-ish phpdoc comment and type inference.

I just thought of one thing: what if we declare global types using .d.ts files and typescript syntax? Just a random idea, I did not think deep about problems like specifying php classes in this structure...

And here comes another idea: using files with hack syntax for global type defs! These would supposedly have syntax support from the hack plugins out of the box!

Plugin not yet activated

I'm trying to use this plugin in vscode but the runtime status said "Not yet activated" (see screenshot). I tried to use it using the example reported in the details but nothing appen when I press Ctrl + Space. I also disabled the php.suggest.basic.

What can I do for activating the plugin? Thanks!

image

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.