Giter Site home page Giter Site logo

dlang-vscode's Introduction

D Support for Visual Studio Code

NOTICE: As this extension is not longer under active development it is suggested to migrate to a much more

active project like vscode-dls

and code-d

Build Status (Linux) Build Status (Windows) Dependency Status codecov

D Language Page: https://dlang.org/

Features

  • Syntax Colorization
  • Snippets
  • Autocompletion and code navigation using DCD
  • Formatting using DFMT
  • Linting using Dscanner with code actions for quick check disabling and automatic fixing for :
    • Deprecated alias syntax
    • Deprecated use of delete
    • Imports not being sorted
  • Code upgrade using Dfix
  • Profiling using D Profile Viewer
  • Integration with Dub using VSCode commands and tasks
  • Dustmite integration

In order to use DCD, dfmt, Dscanner, dfix and D Profile Viewer you must have Dub installed on your system. Dub will then fetch, build and use the packages automatically.

Though this extension lacks a debugger integration, debugging can easily be done using the general purpose Debug extension. After creating a debug configuration and the default dub tasks, simply change the name of the executable and add "preLaunchTask": "build" to build the project when debugging.

Extension Settings

  • d.dmdConf.linux: Path to the dmd configuration file on Linux. Default value: /etc/dmd.conf
  • d.dmdConf.osx: Path to the dmd configuration file on OS X. Default value: /usr/local/etc/dmd.conf
  • d.dmdConf.windows: Path to the dmd configuration file on Windows. Default value: C:\\D\\dmd2\\windows\\bin\\sc.ini
  • d.tools.enabled.dcd: Whether DCD is used or not. Default value: true
  • d.tools.enabled.dfmt: Whether DFMT is used or not. Default value: true
  • d.tools.enabled.dscanner: Whether Dscanner is used or not. Default value: true
  • d.tools.enabled.dfix: Whether Dfix is used or not. Default value: true
  • d.tools.enabled.dProfileViewer: Whether D Profile Viewer is used or not. Default value: true
  • d.tools.dub: Path to the dub executable. Default value: dub
  • d.tools.dcd.client: Path to the system DCD client executable (optional).
  • d.tools.dcd.server: Path to the system DCD server executable (optional).
  • d.tools.dfmt: Path to the system DFMT executable (optional).
  • d.tools.dscanner: Path to the system Dscanner executable (optional).
  • d.tools.dfix: Path to the system Dfix executable (optional).
  • d.dub.compiler: The compiler used by dub when compiling other tools. Possible values:
    • dmd [default]
    • ldc2
    • gdc
  • d.tools.dProfileViewer: Path to the system D Profile Viewer executable (optional).
  • d.dcd.compiler: The compiler used by dub when compiling DCD. Possible values:
    • dmd
    • ldc2
    • gdc
  • d.dcd.tcp: Listen on a TCP socket instead of a UNIX domain socket. This switch has no effect on Windows. Default value: false
  • d.dcd.port: Listens on this port instead of the default port 9166 when TCP sockets are used. Default value: 9166
  • d.dcd.imports: An array of paths that DCD should import on launch. Default value: []
  • d.dfmt.compiler: The compiler used by dub when compiling DFMT. Possible values:
    • dmd
    • ldc2
    • gdc
  • d.dfmt.alignSwitchStatements: Align labels, cases, and defaults with their enclosing switch. Default value: true
  • d.dfmt.braceStyle: Denotes the style for using curly braces in code blocks. Possible values:
    • allman [default]
    • otbs
    • stroustrup
  • d.dfmt.endOfLine: Line ending file format. Possible values:
    • lf [default]
    • cr
    • crlf
  • d.dfmt.softMaxLineLength: The formatting process will usually keep lines below this length. Default value: 80
  • d.dfmt.maxLineLength: Forces hard line wrapping after the amount of characters specified. Default value: 120
  • d.dfmt.outdentAttributes: Decrease the indentation level of attributes. Default value: true
  • d.dfmt.spaceAfterCast: Insert space after the closing parenthesis of a cast expression. Default value: true
  • d.dfmt.selectiveImportSpace: Insert space after the module name and before the ':' for selective imports. Default value: true
  • d.dfmt.splitOperatorAtLineEnd: Place operators on the end of the previous line when splitting lines. Default value: false
  • d.dfmt.compactLabeledStatements: Place labels on the same line as the labeled switch, for, foreach, or while statement. Default value: true
  • d.dscanner.compiler: The compiler used by dub when compiling Dscanner. Possible values:
    • dmd
    • ldc2
    • gdc
  • d.dfix.compiler: The compiler used by dub when compiling Dfix. Possible values:
    • dmd
    • ldc2
    • gdc
  • d.dProfileViewer.compiler: The compiler used by dub when compiling D Profile Viewer. Possible values:
    • dmd
    • ldc2
    • gdc

Note: these dfmt formatting options have yet to be implemented in dfmt itself and won't affect formatting for now:

  • d.dfmt.alignSwitchStatements
  • d.dfmt.outdentAttributes

Extension Commands

  • Create Default Tasks: creates a default tasks.json file for VSCode containing standard dub tasks such as build, run, test and clean
  • Run Dfix: runs dfix on either the currently opened files or the entire workspace
  • See Program Profile: runs d-profile-viewer and displays the profiling results as a HTML page
  • Init Package: creates a new dub package in the current directory
  • Fetch Package: fetches a dub package
  • Remove Package: removes a dub package
  • Upgrade Package Dependencies: upgrade a package's dependencies
  • Convert Dub File Format: converts dub.json to SDL format or dub.sdl to JSON format
  • Dustmite: tries to build the project and sends the compiler output to Dustmite
  • Install Tools: shows tools that can be installed automatically

Commands in the Dlang Actions group are meant for automatic problem fixing.

Manual installation

You have to install the SDLang extension in order to get dlang-vscode to work (it is an extension depency).

git clone https://github.com/dlang-vscode/dlang-vscode
git checkout development # if you want to install the latest development version
cd dlang-vscode
npm install
vsce package
code dlang-<version>.vsix

Troubleshooting

  • Error when building tools at extension startup: some tools don't compile with the latest DMD versions. Solutions:
    • Setting the d.*.compiler user options to ldc2 or gdc
    • Downgrading your version of DMD to 2.071.x
    • Disabling the tool that doesn't compile with d.tools.enabled.*
  • Currently, the latest stable versions of some tools used are quite old and may have some bugs that have only been fixed in the git HEAD version.

TODO

  • Code coverage
  • GC profiling
  • Range formatting
  • Symbol highlighting/renaming

Original code

This extension derives from the original TextMate bundle for D located here

dlang-vscode's People

Contributors

andrepuel avatar laurenttreguier avatar mattiascibien avatar nikibobi avatar sysint64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

dlang-vscode's Issues

Installer calls fetch/build when settings provide executable dependencies.

After defining these settings:
d.tools.dcd.client
d.tools.dcd.server
d.tools.dfmt
d.tools.dscanner
d.tools.dfix
d.tools.dProfileViewer

D language output indicates the installer attempts to build dependencies:
"
Dub fetch : dfix
Dub build : dfix
Dub fetch : d-profile-viewer
Dub build : d-profile-viewer
Found dcd (client) : dcd-client
Found dcd (server) : dcd-server
DCD : starting server...
Found dfmt : dfmt
Found dscanner : dscanner
"

If these settings are defined, these installation steps should (probably?) be skipped.

Custom Paths for Executables

We need to have configurations for those settings:

  • DUB
  • DCD (eventually)

They shoudl live in their own namespace. Proposed is d so the config json will be like:

"d": {
    "dub": "C:\\hello\\dub.exe"
    //others
}

@LaurentTreguier what do you think?

Can't "go to declaration" on module name

Hello.

Currently it is not possible to ctrl+click module name in the import list and go to actual source file.
DCD complains in the background that:

2017-02-28T23:57:13.740:autocomplete.d:findDeclaration:135 Could not find symbol declaration

What is more interesting is the fact, that if you use fully qualified symbol name (for example std.stdio.writeln) and click on the module name (stdio in this example) it will properly open stdio.d file without any complains from DCD.

bug

Is it possible that VC is setting wrong Symbol Type when lookup is done in import list?

UDA highlighting

the UDA is not highlighted examples:

@Field bool resizable = true;
@ViewWidget Button okButton;

@OnClickListener("okButton")
void onOkButtonClick(Widget widget) {
    ...
}

DUB Commands

Add support for DUB commands like dub run, dub compile, dub test and so on.

Never used variable turns off autocomplete

With this code autocomplete works fine:

import deimos.ncurses;

void main()
{
    deimos.ncurses.initscr();
    deimos.ncurses.endwin();  /// Stil works
}

But with this not:

import deimos.ncurses;
alias NC = deimos.ncurses;

void main()
{
    deimos.ncurses.initscr();
    immutable hello = toStringz("Hello World");
    deimos.ncurses.endwin();  /// Never used varable hello turns of autocomplete
}

Fix code snippets

Fix some code snippets as they stil have some Textmate macros in them

Version 0.8.1

@mattiascibien With this commit, a nasty bug has been resolved : DCD would try to use a system wide DCD installation instead of the one provided by dub ; which means the extension currently crashes whenever DCD is not installed globally...
I think there should be a 0.8.1 bugfix release on the VSCode marketplace.

Import alias turns off autocomplete

With this code autocomplete works fine:

import deimos.ncurses;

void main()
{
    deimos.ncurses.initscr();
}

But with this not:

import deimos.ncurses;
alias NC = deimos.ncurses;

void main()
{
    NC.initscr();
}

Syntax highlighting is missing some D language features

Every now and then, issues pop up about syntax highlighting (see #40, #41, #46). The syntax file in this extension is from this textmate bundle, and although it's working for the most part, it's still not totally complete.
I have started a rewrite from scratch of the language syntax file, and looking at the D specs, and specifically the lexical specs (which is the only part I've really looked at for now), I can see that a bunch of things, although probably not commonly used, are missing.

auto hexString = x"fftt"; // hex string with invalid, non-hexadecimal characters (tt)
auto delimitedString = q"<hello>"; // delimited string
auto tokenString = q{delimitedString ~ " world"}; // token string

These are all valid D strings (except for the first one), yet only the classic string parts actually get highlighted (it should be visible on Github as the syntax file used is the same), and the error in the first string could (and should) be highlighted as invalid.
Plus, using JSON format instead of XML should result in a smaller file which will be arguably more readable.
The work on the new syntax file is in the new-syntax branch. When it's ready, its commits should probably be squashed into a single one before getting pulled in master to prevent polluting the commit history.

Allow config file for Dscanner linting

I don't need some of the linting features and they just pollute warnings/errors window. Add an option to specify a config file location and use that, or have the process be created with a cwd set to the workspace root. I think dscanner checks the cwd for a dscanner.ini file.

DCD support?

Just noticed this project, very exciting!
Is there intent to support DCD for autocomplete and co?

Presence on the Visual Studio Code Marketplace

It's been 1 year since the deprecation notice, 2 years since the last commit before that, and 3 years since the last tagged version.
I think we can safely say that this extension has served its time. However, it's still published and available on the Marketplace, and I'm thinking that it might not be a good idea to keep it there, since it's been unmaintained for quite some time now.

I'm creating this issue after seeing someone on the community Discord server asking for which extension to use: when searching for "Dlang", there are 3 choices, but with no clear indication right away that one of them is not maintained.

Output Window Changes Cursor Focus When Hiding.

When vscode is opened to a workspace or file that causes the D extension to load. The output window steals/shifts focus from whatever the user was currently doing, once everything is loaded and the output window closes. If a search was being done (ctrl+shift+F) the focus is shifted away from the search edit box and to the main window. Same for the command panel (ctrl+P).

Potentially related code:
https://github.com/dlang-vscode/dlang-vscode/blob/v0.9.0/src/extension.ts#L229

Error while building dependencies with DUB

VS Code gives this error message while building dependencies for extension.

C:\Users\mcferden\AppData\Roaming\dub\packages\experimental_allocator-2.70.0-b1\experimental_allocator\src\std\experimental\allocator\package.d(322, 13): Error: std.experimental.allocator.common.Ternary at C:\Users\mcferden\AppData\Roaming\dub\packages\experimental_allocator-2.70.0-b1\experimental_allocator\src\std\experimental\allocator\common.d(14, 1) conflicts with std.typecons.Ternary at D:\D\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(7427, 1),C:\Users\mcferden\AppData\Roaming\dub\package

I'm using DMD 2.072.0 and DUB 1.0.0 on Windows OS.

Multiline errors support

Example:

source/mir/ndslice/dynamic.d(419,27): Error: CTFE failed because of previous errors in isPermutation
source/mir/ndslice/dynamic.d(419,9):        while evaluating: static assert([3LU, 0LU, 1LU, 2LU].isPermutation)

Extra Unused Symbols AST Dscanner

When I look for symbols in a source file the top is flooded with types that aren't defined in the source file. This results in 20+ duplicate symbols that just point to the first line of the source file. It looks like it is using variable declaration types as symbols.

For example manually running "dscanner --ast" on a file I find the following:

<declaration>
   <variableDeclaration>
      <type pretty="Vec3">
         <type2>
            <symbol>
               <identifierOrTemplateChain>
                  <identifierOrTemplateInstance>
                     <identifier>Vec3</identifier>
                  </identifierOrTemplateInstance>
               </identifierOrTemplateChain>
            </symbol>
         </type2>
      </type>
      <declarator line="111">
         <name>position</name>
      </declarator>
   </variableDeclaration>
</declaration>

But when I try looking for the symbol "position", it can't find any in vscode. Which makes me think it ended up as one of the 20 Vec3 symbols.

Could potentially use the output of "ctags" rather than parsing the AST from dscanner.

Error with hints

The extension is giving me two invalid hints:

screenshot at 2016-11-18 04-10-18

I realize this error is from one of the third party tools this extension use. Please point me out where should I post this.

Here's the code tested:

import std.algorithm: partition3;
import std.stdio: readln, writeln;

private void quicksort(T)(T[] arr) {
	if (arr.length >= 2) {
		auto p = partition3(arr, arr[0]);
		p[0].quicksort;
		p[2].quicksort;
	}
}

void main() {
	auto arr = [10, 9, 8];
	arr.quicksort;
	arr.writeln;
	readln();
}

Documentation display is broken

Currently, documentation is not always displayed properly.
Some characters used in markdown are not escaped. For example, any * pair will be interpreted by VSCode and the text in between the two * will be shown in italic.
Some parts of the documentation use a $(UL something) syntax that are only translated to `something`, when it should be something else entirely (here with UL it should be a list with some LI elements inside).
Furthermore, something like $(UL text (parens) other text) will be replaced by the simple regex with `text (parens` other text) because it stops at the first closing parenthesis.

Long story short, the parsing done for documentation should be a lot more complex than it currently is (a couple of regex replacements and separation of text and code examples).

Support common IDE features

I think you're doing a great job, and your extension has the potential of being the standard for dlang, even better than code-d/serve-d. It's great that you release often and keep things up-to-date, and it just works without issues (at least for me).

Now it's time to add some IDE features that we desperately need. Please feel free to use this issue as a meta-issue for other IDE features sub-issues.

  • When doing code completion of functions, on accept, insert it as a snippet pre-populated with parameters signatures that user can tab to each and fill with appropriate arguments.
  • Find all references. This should work for user-defined types, local/global variables, fields, parameters, ... etc.
  • Call hierarchy. Invoking this on a function should give a tree of all the callers of that function.
  • Type hierarchy. It should be possible to invoke this on:
    • A function: to get a tree of all functions from base classes that this function is overriding, and all functions from derived classes that override this function.
    • A class or an interface: to get a tree of all derived and base classes (in case of a class) and all classes that implement the interface.
  • Semantic highlighting: User can configure which color/bold/italic for D symbols based on their types (e.g. class, interface, static function, static variable, member function, member variable, local variable, parameter, alias, string, character, module, keyword, template parameter, enum type, enum item, ... etc).
  • Some refactoring features:
    • Find and replace all occurrences of a particular symbol.
    • Suggest when cursor is on a struct or class field to auto implement a getter or setter property.

Please add more if you remember anything else.

To help you get started, all the above features have been implemented successfully for a very popular C++ vscode extension called cquery cquery-server / cquery-extension. Please take a look.

Install fail

I installed the plugin, it tried to fetch and build dependent tools.
This failed pretty spectacularly.

In addition to not working, it also took ages to build!
Why wouldn't we just pull a binary? Binary distribution is best distribution ;)

Dub fetch : dfix
Dub build : dfix
Error: linker exited with status 1
C:\dev\D\dmd2\windows\bin\dmd.exe failed with exit code 1.
Dub fetch : d-profile-viewer
Dub build : d-profile-viewer
Dub fetch : dcd
Dub build : dcd (client)
Dub fetch : dcd
Dub build : dcd (server)
DCD : starting server...
Dub fetch : dfmt
Dub build : dfmt
src\dfmt\main.d(90,38): Deprecation: function `std.exception.enforceEx!(GetOptException).enforceEx!bool.enforceEx` is deprecated - Use `enforce`. `enforceEx` will be removed with 2.089.
Error: linker exited with status 1
C:\dev\D\dmd2\windows\bin\dmd.exe failed with exit code 1.
Dub fetch : dscanner
Dub build : dscanner
Invalid source/import path: C:\Users\Manu\AppData\Local\dub\packages\dscanner-0.5.3\dscanner\bin
src\dscanner\analysis\unused.d(314,18): Error: no property `statementNoCaseNoDefault` for type `const(WithStatement)`
C:\dev\D\dmd2\windows\bin\dmd.exe failed with exit code 1.

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.