<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>Athens, Greece
$ arthur.vercruysse@ugent.be (A. Vercruysse); JulianAndres.RojasMelendez@UGent.be (J. A. Rojas);
pieter.colpaert@ugent.be (P. Colpaert)</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Bringing IDE Support to JSON-LD with the Language Server Protocol</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Arthur Vercruysse</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Julián Andrés Rojas</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Pieter Colpaert</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>IDLab, Department of Electronics and Information Systems, Ghent University - imec</institution>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2023</year>
      </pub-date>
      <volume>000</volume>
      <fpage>0</fpage>
      <lpage>0002</lpage>
      <abstract>
        <p>JSON-LD is a popular data format used to describe and share semantic data on the web. However, creating and editing JSON-LD documents can be a challenging task, especially when dealing with complex contexts that include many properties. The existing JSON editing functionality may not sufice for developers, and a JSON-LD editor could greatly enhance their experience. In this paper, we introduce a JSON-LD Language Server based on the Language Server Protocol (LSP) that empowers text editors compatible with the LSP (e.g., Visual Studio Code and NeoVim) with IDE functionality, including autocompletion suggestions based on the defined context, semantic highlighting and renaming identifiers inside the document. We believe that a JSON-LD LSP will enhance developer ergonomics and promote its adoption. Moreover, we see high potential for additional features that can be added such as hovering, go-to-definition and code actions like flattening or structuring of JSON-LD documents.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Linked Data</kwd>
        <kwd>JSON-LD</kwd>
        <kwd>Developer UX</kwd>
        <kwd>Tool</kwd>
        <kwd>Language Server</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>Creating new JSON-LD documents is a dificult task, before the developer knows the defined
aliases, he has to scrupulously explore the context and remember the defined names. Accidental
typos can result in broken linked data and to the best of our knowledge, there are no tools
in existence that could assist in preventing this issue. We show that using a language server
for JSON-LD helps alleviate this problem and can also bring better developer ergonomics for
experienced and new semantic web developers.</p>
      <p>
        Similar eforts have been made before, but never for JSON-LD. For example, the Yasgui editor 2,
a popular SPARQL human query interface, provides autocompletion based on the LOV API[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
Plugins can also add autocompletion based on domain knowledge. These capabilities are built
into the deployed editor and can only be used with Yasgui. Stardog created open-source LSPs
for turtle, TRIG, SPARQL, and more, however, they focus only on correct syntax and keyword
auto-completion[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>
        In this paper, we introduce a JSON-LD language server implementation following the
Language Server Protocol (LSP), a JSON RPC protocol designed by Microsoft3. LSP is designed to
simplify the process of integrating language-specific logic into an editor, removing the need to
implement language-specific logic into each editor, and reducing the ( * ) complexity to a
much more manageable ( + ) complexity[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ].
      </p>
      <p>A full LSP implementation supplies the editor with IDE features, including autocompletion,
diagnostics, formatting, identifier renaming, hovering, go-to-definition and generic code actions
like extract highlighted code to function. Not all features have to be implemented, the Language
Server and the editor communicate their capabilities and only use what is supported by both
parties.</p>
      <p>LSP source code and installation instructions are available on GitHub (MIT)4.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Features of the JSON-LD language server</title>
      <p>This section covers the implemented features, explaining what they are and how they benefit
the developer.</p>
      <p>• Autocompletion enables the developer to type less and thus make fewer mistakes. The
created suggestions are derived from the defined context 5 and defined entity ids inside
the document. This way developers don’t have to remember aliases by heart and can
more easily explore the context. An example can be seen in Figure 1. It should be possible
to write foaf: and get autocompletion suggestions for all defined predicates in the foaf
namespace, but this is not yet supported.
• Diagnostics represent errors and warnings in the file. Our language server only supports
syntax errors but emitting a warning when an undefined property is encountered, can be
an easy extension.</p>
      <sec id="sec-2-1">
        <title>2Yasgui - SPARQL editor</title>
        <p>3Microsoft: Language Server Protocol
4Github: https://github.com/ajuvercr/jsonld-lsp
5Only simple and explicit aliases are extracted from the context, context overloading or scoped contexts are not
supported.</p>
        <p>• Semantic Highlighting difers from syntax highlighting. The syntax of JSON-LD is
very easy, but semantic highlighting highlights keywords, identifiers and tokens
diferently. Other semantic highlighting functionality includes highlighting defined/undefined
properties and highlighting entity ids and types, these are however not implemented.
• Renaming, in our LSP, allows the developer to rename defined identifiers and their
references. An example of renaming an entity can be seen in Figure 2, first the editor will
ask for a new name, then all occurrences are renamed.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Demo</title>
      <p>Our demo presents an implementation of a JSON-LD Language Server according to the Language
Server Protocol (LSP), developed using the Rust programming language based on a basic LSP
implementation6. The full source code and installation instructions can be found on GitHub
(MIT). A demo version of the LSP is available on the web. The full LSP is available as a VS Code
extension and as a NeoVim LSP.</p>
      <p>The Language server is compiled to WASM to be integrated inside the VSCode extension.
This enables the extension to be a Web Extension7, which are available in online Visual Studio
Code instances like github.dev.</p>
      <p>Extracting predicate mappings from the context is handled by the JSON-LD crate8. Some</p>
      <sec id="sec-3-1">
        <title>6Tower LSP - Crate by Eyal Kalderon</title>
        <p>7https://code.visualstudio.com/api/extension-guides/web-extensions
8JSON-LD - Crate by Timothée Haudebourg
parts of the JSON-LD crate can’t compile to WASM, because of internal Rust requirements9 and
required some rewriting of the crate.</p>
        <p>Parsing the JSON structure is done with the Chumsky crate10. This was no easy task because
the moment the Language Server should suggest completion options, the document is no valid
JSON anymore. This required a special internal JSON structure allowing parts of a dictionary to
be invalid.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Conclusion</title>
      <p>This JSON-LD LSP is an example of what impact developer tools can have on productivity and
therefore also on adoption. The same ideas can be applied to other semantic data formats to
help write but also, with hover functionality, to help understand the data more easily.</p>
      <p>This demonstration merely scratches the surface of the vast capabilities of a JSON-LD LSP.
By leveraging fully-interpreted contexts, the LSP can provide more contextually-relevant
suggestions, taking into account context overloading and scoped contexts. Additionally, the LSP’s
functionality can be expanded to include the interpretation of referenced vocabularies, allowing
completion for compacted predicates, like foaf:knows. Despite its current limitations, the LSP
already enhances the developer experience by facilitating the creation and editing of JSON-LD
documents.</p>
      <p>On the development side, this demo contributes to the open-source community. There are
not many examples of Language Servers written in Rust and compiled to WASM to be included
in a Visual Studio Code extension. Hopefully, this implementation starts a cascade of developer
tools for the semantic web community.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>M.</given-names>
            <surname>Sporny</surname>
          </string-name>
          , G. Kellogg,
          <string-name>
            <given-names>M.</given-names>
            <surname>Lanthaler</surname>
          </string-name>
          ,
          <source>JSON-LD 1.1"</source>
          , W3C Recommendation,
          <year>W3C</year>
          ,
          <year>2020</year>
          . Https://www.w3.org/TR/json-ld/.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Taelman</surname>
          </string-name>
          , Ruben and Van Herwegen,
          <article-title>Joachim and Vander Sande, Miel and Verborgh, Ruben, Components.js : semantic dependency injection</article-title>
          ,
          <source>SEMANTIC WEB 14</source>
          (
          <year>2023</year>
          )
          <fpage>135</fpage>
          -
          <lpage>153</lpage>
          . URL: http://dx.doi.org/10.3233/SW-222945.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>P.-Y.</given-names>
            <surname>Vandenbussche</surname>
          </string-name>
          , G. Atemezing,
          <string-name>
            <given-names>M.</given-names>
            <surname>Poveda-Villalón</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Vatant</surname>
          </string-name>
          ,
          <article-title>Linked open vocabularies (lov): A gateway to reusable semantic vocabularies on the web</article-title>
          ,
          <source>Semantic Web</source>
          <volume>8</volume>
          (
          <year>2017</year>
          )
          <fpage>437</fpage>
          -
          <lpage>452</lpage>
          . doi:
          <volume>10</volume>
          .3233/SW-160213.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4] Stardog - language
          <source>servers github</source>
          ,
          <year>2008</year>
          . URL: https://github.com/stardog-union/
          <article-title>stardog-language-servers.</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>H.</given-names>
            <surname>Bünder</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Kuchen</surname>
          </string-name>
          ,
          <article-title>Towards multi-editor support for domain-specific languages utilizing the language server protocol</article-title>
          , in: S. Hammoudi,
          <string-name>
            <given-names>L. F.</given-names>
            <surname>Pires</surname>
          </string-name>
          ,
          <string-name>
            <surname>B.</surname>
          </string-name>
          Selić (Eds.),
          <source>Model-Driven Engineering and Software Development</source>
          , Springer International Publishing, Cham,
          <year>2020</year>
          , pp.
          <fpage>225</fpage>
          -
          <lpage>245</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          <article-title>9Fetching a resource in WASM is not Send or Sync, which is required in async environments 10Chumsky - Crate by Joshua Barretto</article-title>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>