dls 0.1.1

D Language Server


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

D Language Server

This is a work in progress...

DLS implements the server side of the Language Server Protocol (LSP) for the D programming language. It does not contain any language feature itself (yet), but uses existing components and provides an interface to work with the LSP. It currently provides:

  • formatting using DFMT
  • code completion using DCD

Client side configuration

All these keys should be formatted as d.dls.[section].[key] (e.g. d.dls.formatter.endOfLine).

Section: generalTypeDefault value
importPathsstring[][]
Section: formatterTypeDefault value
endOfLine`"lf""cr""crlf"`"lf"
maxLineLengthnumber120
dfmtBraceStyle`"allman""otbs""stroustrup"`"allman"
dfmtSoftMaxLineLengthnumber80
dfmtAlignSwitchStatementsbooleantrue
dfmtOutdentAttributesbooleantrue
dfmtSplitOperatorAtLineEndbooleanfalse
dfmtSpaceAfterCastbooleantrue
dfmtSpaceAfterKeywordsbooleantrue
dfmtSpaceBeforeFunctionParametersbooleanfalse
dfmtSelectiveImportSpacebooleantrue
dfmtCompactLabeledStatementsbooleantrue

Caveats

The server may delegate a few operations to the client-side extension dpending on the language client's capabilities. The client should watch these files for the server to work properly:

  • dub.selections.json
  • dub.json
  • dub.sdl

If the client supports dynamic registration of the workspace/didChangeWatchedFiles method, then the server will automatically register file watching. If the client doesn't support dynamic registration however, the client-side extension will need to manually do it. The server needs to know at least when dub.selections.json files change to properly provide completion support. If dub.json and dub.sdl are also watched, dub.selections.json will automatically be regenerated and then it will be used for completion support.

As support for messages regarding workspace folders are not yet supported in Visual Studio Code (used for testing the server), dls also lacks support for multiple workspace folders for now.

Example usage

Below is the code of a minimal Visual Studio Code extension using a hardcoded path to the dls binary:

'use strict';

import * as cp from 'child_process';
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';

export function activate(context: vscode.ExtensionContext) {
    const serverOptions: lc.ServerOptions = {
        command: 'path/to/the/dls/binary'
    };
    const clientOptions: lc.LanguageClientOptions = {
        documentSelector: [{ scheme: 'file', language: 'd' }],
        synchronize: {
            configurationSection: 'd.dls'
        }
    };
    const client = new lc.LanguageClient('dlang-vscode', 'D Language', serverOptions, clientOptions);
    context.subscriptions.push(client.start());
}

export function deactivate() {
}

Extract from the properties section of the package.json file:

{
    "title": "D",
    "properties": {
        "d.dls.general.importPaths": {
            "type": "array",
            "default": []
        },
        "d.dls.formatter.endOfLine": {
            "enum": [
                "lf",
                "cr",
                "crlf"
            ],
            "default": "lf"
        },
        "d.dls.formatter.maxLineLength": {
            "type": "number",
            "default": 120
        },
        "d.dls.formatter.dfmtBraceStyle": {
            "enum": [
                "allman",
                "otbs",
                "stroustrup"
            ],
            "default": "allman"
        },
        "d.dls.formatter.dfmtSoftMaxLineLength": {
            "type": "number",
            "default": 80
        },
        "d.dls.formatter.dfmtAlignSwitchStatements": {
            "type": "boolean",
            "default": true
        },
        "d.dls.formatter.dfmtOutdentAttributes": {
            "type": "boolean",
            "default": true
        },
        "d.dls.formatter.dfmtSplitOperatorAtLineEnd": {
            "type": "boolean",
            "default": false
        },
        "d.dls.formatter.dfmtSpaceAfterCast": {
            "type": "boolean",
            "default": true
        },
        "d.dls.formatter.dfmtSpaceAfterKeywords": {
            "type": "boolean",
            "default": true
        },
        "d.dls.formatter.dfmtSpaceBeforeFunctionParameters": {
            "type": "boolean",
            "default": false
        },
        "d.dls.formatter.dfmtSelectiveImportSpace": {
            "type": "boolean",
            "default": true
        },
        "d.dls.formatter.dfmtCompactLabeledStatements": {
            "type": "boolean",
            "default": true
        }
    }
}
Authors:
  • Laurent Tréguier
Dependencies:
dfmt, dcd, dub
Versions:
0.26.2 2020-Mar-20
0.26.1 2020-Jan-25
0.26.0 2019-Dec-03
0.25.19 2019-Oct-29
0.25.18 2019-Oct-28
Show all 158 versions
Download Stats:
  • 0 downloads today

  • 2 downloads this week

  • 3 downloads this month

  • 13931 downloads total

Score:
2.2
Short URL:
dls.dub.pm