Sublime Text PHP開發設定檔

安裝intelephense lsp server

npm install -g intelephense

sublimetext 安裝套件 LSP-intelephens

LSP-intelephense 設定

{
    "schemes": ["file", "buffer"],
    "auto_complete_selector": "punctuation.accessor | punctuation.definition.variable | punctuation.separator.namespace | punctuation.definition.tag.begin",
    "initializationOptions": {
        "clearCache": false,
        // "storagePath": "${temp_dir}/intelephense",
        // "globalStoragePath": "${home}/.intelephense",

        // if you want to use a premium license, you can either paste the key directly
        // or paste it into a file and provide its absolute path here
        // "licenceKey": "${packages}/User/intelephense-license.txt",
    },
    // @see configuration in https://github.com/bmewburn/vscode-intelephense/blob/master/package.json
    "settings": {
        // There are quite a lot of settings for intelephense...
        // For a full list, you can check the link above or just use LSP-json for autocompletion.

        // Enable a code lens that shows an abstract and interface implementations count and command to peek locations.
        "intelephense.codeLens.implementations.enable": false,

        // Enable a code lens that shows method override count and command to peek locations.
        "intelephense.codeLens.overrides.enable": false,

        // Enable a code lens that indicates if a method has a parent implementation and command to peek location.
        "intelephense.codeLens.parent.enable": false,

        // Enable a code lens that shows a reference count and command to peek locations.
        "intelephense.codeLens.references.enable": false,

        // Enable a code lens that shows a trait usages count and command to peek locations.
        "intelephense.codeLens.usages.enable": false,

        // Resolves `ArrayAccess` and `Traversable` implementations that are unioned with a typed array to generic syntax. eg `ArrayAccessOrTraversable|ElementType[]` => `ArrayAccessOrTraversable<mixed, ElementType>`.
        "intelephense.compatibility.correctForArrayAccessArrayAndTraversableArrayUnionTypes": true,

        // Resolves `BaseClass|static` union types to `static` instead of `BaseClass`.
        "intelephense.compatibility.correctForBaseClassStaticUnionTypes": true,

        // Prefer `@psalm-` and `@phpstan-` prefixed `@return`, `@var`, `@param` tags when determining symbol types.
        "intelephense.compatibility.preferPsalmPhpstanPrefixedAnnotations": false,

        // Global namespace constants and functions will be fully qualified (prefixed with a backslash).
        "intelephense.completion.fullyQualifyGlobalConstantsAndFunctions": false,

        // Use declarations will be automatically inserted for namespaced classes, traits, interfaces, functions, and constants.
        "intelephense.completion.insertUseDeclaration": true,

        // The maximum number of completion items returned per request.
        "intelephense.completion.maxItems": 100,

        // PHP permits the calling of static methods using the object operator eg `$obj->myStaticMethod();`. If you would prefer not to have static methods suggested in this context then set this value to `false`. Defaults to `true`.
        "intelephense.completion.suggestObjectOperatorStaticMethods": true,

        // Method and function completions will include parentheses and trigger parameter hints.
        "intelephense.completion.triggerParameterHints": true,

        // Enables argument count diagnostics.
        "intelephense.diagnostics.argumentCount": true,

        // Enables deprecated diagnostics.
        "intelephense.diagnostics.deprecated": true,

        // Enables duplicate symbol diagnostics.
        "intelephense.diagnostics.duplicateSymbols": true,

        // Enables diagnostics in embedded languages.
        "intelephense.diagnostics.embeddedLanguages": true,

        // Enables diagnostics.
        "intelephense.diagnostics.enable": true,

        // Enables reporting of problems associated with method and class implementations. For example, unimplemented methods or method signature incompatibilities.
        "intelephense.diagnostics.implementationErrors": true,

        // Enables reporting of various language constraint errors.
        "intelephense.diagnostics.languageConstraints": true,

        // This setting turns off type checking for the `mixed` type. This is useful for projects that may have incomplete or innacurate typings. Set to `false` to make type checking more thorough by not allowing `mixed` to satisy any type constraint. This setting has no effect when `relaxedTypeCheck` is `true`.
        "intelephense.diagnostics.noMixedTypeCheck": true,

        // This setting makes type checking less thorough by allowing contravariant (wider) types to also satisfy a type constraint. This is useful for projects that may have incomplete or innacurate typings. Set to `false` for more thorough type checks. When this setting is `true`, the `noMixedTypeCheck` setting is ignored.
        "intelephense.diagnostics.relaxedTypeCheck": true,

        // Controls when diagnostics are run.
        //  - onType: Diagnostics will run as changes are made to the document.
        //  - onSave: Diagnostics will run when the document is saved.
        "intelephense.diagnostics.run": "onType",

        // Enables diagnostics on type compatibility of arguments, property assignments, and return statements where types have been declared.
        "intelephense.diagnostics.typeErrors": true,

        // Enables undefined class constant diagnostics.
        "intelephense.diagnostics.undefinedClassConstants": true,

        // Enables undefined constant diagnostics.
        "intelephense.diagnostics.undefinedConstants": true,

        // Enables undefined function diagnostics.
        "intelephense.diagnostics.undefinedFunctions": true,

        // Enables undefined method diagnostics.
        "intelephense.diagnostics.undefinedMethods": true,

        // Enables undefined property diagnostics.
        "intelephense.diagnostics.undefinedProperties": true,

        // DEPRECATED. Use the setting for each symbol category.
        "intelephense.diagnostics.undefinedSymbols": true,

        // Enables undefined class, interface and trait diagnostics.
        "intelephense.diagnostics.undefinedTypes": true,

        // Enables undefined variable diagnostics.
        "intelephense.diagnostics.undefinedVariables": true,

        // Enables unexpected token diagnostics.
        "intelephense.diagnostics.unexpectedTokens": true,

        // Enables unused variable, private member, and import diagnostics.
        "intelephense.diagnostics.unusedSymbols": true,

        // The directory of the entry point to the application (directory of index.php). Can be absolute or relative to the workspace folder. Used for resolving script inclusion and path suggestions.
        "intelephense.environment.documentRoot": "",

        // The include paths (as individual path items) as defined in the include_path ini setting or paths to external libraries. Can be absolute or relative to the workspace folder. Used for resolving script inclusion and/or adding external symbols to folder.
        "intelephense.environment.includePaths": [],

        // A semver compatible string that represents the target PHP version. Used for providing version appropriate suggestions and diagnostics. PHP 5.3.0 and greater supported.
        "intelephense.environment.phpVersion": "8.3.0",

        // When enabled '<?' will be parsed as a PHP open tag. Defaults to true.
        "intelephense.environment.shortOpenTag": true,

        // Configure glob patterns to make files available for language server features. Inherits from files.associations.
        "intelephense.files.associations": [
            "*.php",
            "*.phtml"
        ],

        // Configure glob patterns to exclude certain files and folders from all language server features. Inherits from files.exclude.
        "intelephense.files.exclude": [
            "**/.git/**",
            "**/.svn/**",
            "**/.hg/**",
            "**/CVS/**",
            "**/.DS_Store/**",
            "**/node_modules/**",
            "**/bower_components/**",
            "**/vendor/**/{Tests,tests}/**",
            "**/.history/**",
            "**/vendor/**/vendor/**"
        ],

        // Maximum file size in bytes.
        "intelephense.files.maxSize": 1000000,

        // Controls formatting style of braces
        //  - per: PHP-FIG PER-CS style. A mix of Allman and K&R. https://www.php-fig.org/per/coding-style/
        //  - allman: Allman. Opening brace on the next line.
        //  - k&r: K&R (1TBS). Opening brace on the same line.
        "intelephense.format.braces": "per",

        // Enables formatting.
        "intelephense.format.enable": true,

        // DEPRECATED. Don't use this. Go to command palette and search for enter licence key.
        "intelephense.licenceKey": "",

        // Maximum memory (in MB) that the server should use. On some systems this may only have effect when runtime has been set. Minimum 256.
        "intelephense.maxMemory": 0,

        // An object that describes the format of generated class/interface/trait phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.
        "intelephense.phpdoc.classTemplate": {
            "summary": "$1",
            "tags": [
                "@package ${1:$SYMBOL_NAMESPACE}"
            ]
        },

        // An object that describes the format of generated function/method phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.
        "intelephense.phpdoc.functionTemplate": {
            "summary": "$1",
            "tags": [
                "@param ${1:$SYMBOL_TYPE} $SYMBOL_NAME $2",
                "@return ${1:$SYMBOL_TYPE} $2",
                "@throws ${1:$SYMBOL_TYPE} $2"
            ]
        },

        // An object that describes the format of generated property phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.
        "intelephense.phpdoc.propertyTemplate": {
            "summary": "$1",
            "tags": [
                "@var ${1:$SYMBOL_TYPE}"
            ]
        },

        // Adds `@return void` to auto generated phpdoc for definitions that do not return a value.
        "intelephense.phpdoc.returnVoid": true,

        // 
        //  - snippet: Auto generated phpdoc is returned in snippet format. Templates are partially resolved by evaluating phpdoc specific variables only.
        //  - text: Auto generated phpdoc is returned as plain text. Templates are resolved completely by the server.
        "intelephense.phpdoc.textFormat": "snippet",

        // Fully qualified names will be used for types when true. When false short type names will be used and imported where appropriate. Overrides intelephense.completion.insertUseDeclaration.
        "intelephense.phpdoc.useFullyQualifiedNames": false,

        // Glob patterns matching files and folders that should be excluded from references search.
        "intelephense.references.exclude": [
            "**/vendor/**"
        ],

        // Glob patterns matching files and folders that should be excluded when renaming symbols. Rename operation will fail if the symbol definition is found in the excluded files/folders.
        "intelephense.rename.exclude": [
            "**/vendor/**"
        ],

        // Controls the scope of a namespace rename operation.
        //  - single: Only symbols defined in the current file are affected. For example, this makes a rename of a namespace the equivalent of a single move class operation.
        //  - all: All symbols that share this namespace, not necessarily defined in the current file will be affected. For example it would move all classes that share this namespace to the new namespace.
        "intelephense.rename.namespaceMode": "single",

        // Path to a Node.js executable. Use this if you wish to use a different version of Node.js. Defaults to Node.js shipped with VSCode.
        "intelephense.runtime": "",

        // Configure stub files for built in symbols and common extensions. The default setting includes PHP core and all bundled extensions.
        "intelephense.stubs": [
            "apache",
            "bcmath",
            "bz2",
            "calendar",
            "com_dotnet",
            "Core",
            "ctype",
            "curl",
            "date",
            "dba",
            "dom",
            "enchant",
            "exif",
            "FFI",
            "fileinfo",
            "filter",
            "fpm",
            "ftp",
            "gd",
            "gettext",
            "gmp",
            "hash",
            "iconv",
            "imap",
            "intl",
            "json",
            "ldap",
            "libxml",
            "mbstring",
            "meta",
            "mysqli",
            "oci8",
            "odbc",
            "openssl",
            "pcntl",
            "pcre",
            "PDO",
            "pdo_ibm",
            "pdo_mysql",
            "pdo_pgsql",
            "pdo_sqlite",
            "pgsql",
            "Phar",
            "posix",
            "pspell",
            "random",
            "readline",
            "Reflection",
            "session",
            "shmop",
            "SimpleXML",
            "snmp",
            "soap",
            "sockets",
            "sodium",
            "SPL",
            "sqlite3",
            "standard",
            "superglobals",
            "sysvmsg",
            "sysvsem",
            "sysvshm",
            "tidy",
            "tokenizer",
            "xml",
            "xmlreader",
            "xmlrpc",
            "xmlwriter",
            "xsl",
            "Zend OPcache",
            "zip",
            "zlib"
        ],

        // Anonymous usage and crash data will be sent to Azure Application Insights. Inherits from telemetry.enableTelemetry.
        "intelephense.telemetry.enabled": null,

        // Traces the communication between VSCode and the intelephense language server.
        "intelephense.trace.server": "off",
        "statusText": "{% if server_version %}v{{ server_version }}{% endif %}",
    },
    "selector": "embedding.php",
    "priority_selector": "source.php",
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料