GithubHelp home page GithubHelp logo

rogalmic / vscode-xml-complete Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 16.0 4.67 MB

XML editing helper (using XSD schemaLocation)

License: MIT License

TypeScript 63.52% C# 35.45% Batchfile 0.56% JavaScript 0.47%

vscode-xml-complete's People

Contributors

andersmad avatar devel0 avatar rogalmic 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

Watchers

 avatar  avatar  avatar

vscode-xml-complete's Issues

[XAML/AXAML] Experimentally generate XSD from C# workspace

This experiment is better suited for an XAML/AXAML-specific extension, but only one exists and it is specifically for NoesisGUI.

Why?

As it is, this extension's Avalonia schema is convenient, but comes with major drawbacks for both end-users and maintainers.

  • Schema symbols are manually defined. This limits symbols to only those which are feasible to maintain long-term and are part of Avalonia's API. This excludes third-party Avalonia controls and add-ons. This also means the included XSD may be incompatible depending on the version of Avalonia targeted by a csproj.
  • Schema symbols are manually updated. This also affects maintainability and project compatibility.

The current Avalonia completion source is outdated and partially incompatible with the latest major release of Avalonia: 11.0.0. This release included several breaking changes from the previous major release, 0.10.0. The AvaloniaUI organization provides a upgrade guide for API consumers.

How?

Generating XSD from C# workspace symbols will require either communicating with ms-dotnettools.csharp and/or ms-dotnettools.csdevkit or a first-party solution for analyzing the project's dependency tree for Avalonia assemblies and third-party Avalonia add-ons (those that depend on Avalonia).

Currently, I use Avant Garde's ability to export Avalonia's schema, but it's currently generated from the Avalonia version targeted by Avant Garde rather than the version targeted by the project project. This may be changed later.

Schema on local disk not recognized in settings-file

I added a section to my settings.json in which I wanted to map locally available schemas (on my Mac):

"xmlComplete.schemaMapping": [
        {
        "xmlns": "sap.ui.core",
        "xsdUri": "file:///Users/.../Library/Application%20Support/UI5Experts/ui5-schemas/openui5/1.65.1/sap.ui.core.xsd",
        "strict": true // shows errors instead of tips
        }
    ]

However, IntelliSense does not pick it up.
Once I added the same URI via schemaLocation to the xml file explicitly, everything works as expected.

When XSD not found, just display one error

When the XSD is not found (because none defined in the XML file, or because the one which is defined cannot be accessed (wrong path for example), then there is a warning/error displayed for each tag.
This is not pertinent, would rather have ONE warning/error stating that the XSD file cannot be located (or is not defined).
As when using the extension "Error Lens", this makes the XML file unreadable by having a warning/error on each line.

axaml not recognized

because of AvaloniaUI/avalonia-dotnet-templates#44 new avalonia templates uses axaml in place of xaml extenion.

if rename axaml to xaml then xmlcomplete recognize and format document but I wondering how to set vscode to allow xml complete to work either with axaml extenion file like xaml.

add support for XML catalogs (schema matching: matching, rewriting, ...)

The catalog entries (replace one entry by another) via xmlComplete.schemaMapping works fine and is quite simiar to eclipse's catalog entries:

 {
  "xmlns": "https://github.com/avaloniaui",
  "xsdUri": "https://raw.githubusercontent.com/rogalmic/vscode-xml-complete/master/test/Avalonia/AvaloniaXamlSchema.xsd"
 }

eclipse XML, catalog entry
eclipse XML, rewrite entry

It would be very ood if we could have rewrite options, which is especially usefiul for local files. This feature is available with the standardized xml catalog. The eclipse IDE seems to just wrap this one in a nice editor.

For the setting, we can just add a new one or even better use the xml.catalogs array, see
https://github.com/redhat-developer/vscode-xml/wiki/XMLValidation#xml-catalog-with-xsd.

I did tags, imports etc

I can see that you are working on the project so I want to let you know that I did completion on elements allowed only (also rewrote linter) supporting imports and multiple namespaces.

The thing is that it was a night-time pet project that evolved and its done in the web version (monaco) so not as an extension (a few minor differences) - so when (if) I'm done i better send you the whole thing for manual merge, extension tedt and validation etc.

What do you think?

XML Parser Used.

Hello.

I see this project is using SAX to parse XML and then perform additional logic on the tags output stream.

Does SAX provide full parsing capabilities for the use case of building editor services?

The reason I am asking is because I've implemented a Parser building library in JS:

Which provides editor related infrastructure capabilities:

  • Fault Tolerance / Error Recovery (Does not stop on the first error).
  • Full syntax information collection (e.g location of closing tags).
  • Syntactic Content Assist
  • Multiple start rules.
  • ...

There is also an XML grammar example:

Feel free to contact me if this is of interest to you.

Cheers.
Shahar.

[add] My change-set for merging with restrictive completion, mixed namespaces, import support and linting etc.

Hi @rogalmic,

Here my submit of the "massive change-set" that I hope you like like an merge in! :)

Again, I'm sorry that I did not do this a bunch of git commits and a pull request - but the my pet project kinda grew out of control and it was done on monaco (not vscode) where some types are different, loaders are bad etc.

On top of my head here is what I did/added:

  • only shows allowed tags in context (up one level - not complete tree but ok for far the most cases I'd reckon)
  • import from xsd load other xsd
  • mix of namespaces element on insert - blank/default namespace will insert without namespace prefix - rest will be with
  • mix of namespaces for attributes - allow attributes from groups from imported xsd
  • stricter linting via above and better highlighting of error (e.g. highlights the whole attribute culprit)
  • more strict annotation match and markdown documentation list with attribute enumeration values
  • auto-complete on attribute values: enumeration values (with documentation) or boolean values
  • linting of attribute values
  • inserting a tag now insert both open and closing tag
  • snippets per namespace (via schema settings) and optionally only show snippets for when parent tag is in a [list]
  • root snippets for xml declaration or start of a root element with all the namespaces
  • quick tag snippet: CTRL + SPACE + ENTER, type name, TAB

I have only tested it on my setup - but thats a pwetty complicated scenario as its 2 XSDs - HTML5 and a XSLT'ish clone that circular references each other via import, elements and attributes. So the auto-complete on html element will show <div id=".." myNs:myAttr=".." works with only showing allowed and lint triggers to if not allowed. I have also eliminated optimistic lookups for with/without name space to be more restrictive now that there are multiple XSD loaded at the same time with possible naming conflicts / bad matches - should also be faster like that now its possible.

I did a few renames like base to baseAttributes as i added baseElements. All monaco should be easily changed to vscode and maybe IRange to Range etc. and just completely ignore the classes and main functions like provideCompletionItems - they are very monaco styled and extending my base class stuff that is not here (and not needed). Besides that I think kept perfectly in line with your base (I hope) and kept most intact with not-to-many renames - but I did change types like string to classes if needed, added interfaces etc.

Btw. you can now enable "noImplicitAny": true, in tsconfig.json - I strongly recommend that :)

Source is here: xml.zip

Proposed elements not in accordance with the schema

My schema is very simple (see schema.xsd and data.xml in attached zip file)

  • I define a <Root> element.
  • <Root> can contains (only) <RootChild_A> and <RootChild_B>
  • <RootChild_A> can contains (only) <AChild>
  • <RootChild_B> can contains (only) <BChild>

Within the <Root> element xml-complete suggests to insert all elements (Root, AChild and BChild shouldn't appear here) :

xmlComplete

The Visual Studio XML editor only suggests valid elements :

visualstudio

Use xsd:annotation to show hover and Go To Definition command

Three suggested features (inspired by Visual Studio XML editor) :

  • Show a tooltip when the mouse is over an element name or attribute name. This tooltip show the documentation provided by the xsd:annotation element in the schema.
  • Show the same documentation into the auto complete list
  • Add a "Go to definition" in the context menu

schema matching: resolve workspace variables in xsdUri

I have different workspaces with same named xsd's (different versions) at the same place.
Currently the configuration entries seem to be hard-wired (full local path), it would be useful to be able to use ${workspaceRoot] in this setting.

Example now:

        {
            "xmlns": "http://www.super.web/xsd/SpecialTypes.xsd",
            "xsdUri": "file:////data/projects/project1/external/xsd-files/SpecialTypes.xsd",
            "strict": false
        },

Example with resolving workspaceRoot (there's a workspace folder "xsd" mapped to the path above):

        {
            "xmlns": "http://www.super.web/xsd/SpecialTypes.xsd",
            "xsdUri": "file://${workspaceRoot:xsd}/SpecialTypes.xsd",
            "strict": false
        },

See vscode variables reference.

Elements with same name (but not same schema)

My schema contains two element definitions <Property>. Each one is valid in a specific context and have not the same attribute set (see attached file).

  • <Property> in <ElementA> must have a Identifier attribute.
  • <Property> in <ElementB> must have a Name attribute.

Identifier and Name attributes are suggested by xml-complete for the <Property> element in <ElementA>.

image

Support "Application" Intellisense/Autocomplete

I was just starting out with Avalonia and while there is intellisense, it just seems to be for controls, and nothing relating to Application.

Take the default template (App.axaml) for example:

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="app.App">
    <Application.Styles>
        <FluentTheme Mode="Light" />
    </Application.Styles>
</Application>

If I CTRL+SPACE in there (or even in the MainWindow.axaml), I get nothing but strings found in the list (eg. "blend").
If I type '<', then CTRL+SPACE, I get a full list for Avalonia controls, from AccessText to WrapPanel.
But there's nothing relating to "Application".

Two things that I think "could" relate to adding this feature "may" be found in:
~/.nuget/packages/avalonia/0.10.0/lib/netcoreapp2.0/Avalonia.Styling.xml
~/.nuget/packages/avalonia/0.10.0/lib/netcoreapp2.0/Avalonia.Themes.Fluent.xml

I don't know how your "test" xs for Avalonia is generated, but I saw "Avalonia.Controls.xml" in the nuget directory as well, making me think it was selectively picked, making me also think those others could be added as well.

While I'm here, looking at https://avaloniaui.net/docs/advanced-tutorial/create-a-modern-window where it talks of "TransparencyLevelHint" (which is part of intellisense), I see "AcrylicBlur" doesn't come up as an intellisense option (nothing does for quoted stuff in general).
That is something found in ~/.nuget/packages/avalonia/0.10.0/lib/netstandard2.0/Avalonia.Controls.xml.

Add support for .axaml files

Avalonia had to move to .axaml files, because visual studio caused many bugs with .xaml. Please, add support for .axaml file extension, avalonia uses it by default now.

Thanks

How to set filename pattern or path glob mapping instead of "xmlns"

Using XML:

<AUTOSAR xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://autosar.org/schema/r4.0">
...
</AUTOSAR>

Setting:

    "xmlComplete.schemaMapping":
    [
        {
            "xmlns": "http://autosar.org/schema/r4.0",
            "xsdUri": "file:///C:/Users/s-jiu/Desktop/AP-R19-03/MethodologyAndManifests/AUTOSAR_MMOD_XMLSchema/AUTOSAR_00047.xsd",
            "strict": true // shows errors instead of tips
        }
    ]

But the complete function didn't work.

image

About the error maybe cause by the xmlns recognized as path not namespace, so search for the path "http://autosar.org/schema/r4.0".

So I want know to any setting like xml path/filename glob map to xsd scheme.

Cannot find XSD schema file

In the attached example (.XML file) XML Complete always complains that it cannot find the XSD file. I have triple checked that the file exists at the specified location, and in fact if i open the sa,e XML file in Visual Studio it find the schema and does all the completions according to the schema correctly.
I tried both these syntaxes
xsi:noNamespaceSchemaLocation="file:///c:/Program Files/Memento/Memento Security/build.xsd"
and
xsi:noNamespaceSchemaLocation="c:\Program Files\Memento\Memento Security\build.xsd"

neither work (and they both work with Visual Studio).
xsd_error
xsd_error2

No completion of attributes

IntelliSense does not pick up the attributes of an element specified like that

<xsd:complexType name="_ListItemType">
    <xsd:complexContent>
      <xsd:extension base="n0:_ItemType">
        <xsd:attribute name="icon" type="xsd:string">
          <xsd:annotation>
            <xsd:documentation>The icon belonging to this list item instance.
This can be a URI to an image or an icon font URI.</xsd:documentation>
          </xsd:annotation>
        </xsd:attribute>

I added the schema for your convenience (and test case production ;))
You may Try to add a core:ListItem and complete its properties.
ZIP with schema and sample xml

Cheers,
Oliver

XSD version 1.1

Does the current version support xsd version 1.1. For example, features like:

<xs:unique ref="previouslyDefined">
<xsd:assert test="minPrice le maxPrice"/> 

If not, do you have this in the plan?
Thank you.

RangeError: Maximum call stack size exceeded

Getting this error when using this xsd file.
https://raw.githubusercontent.com/propelorm/Propel/master/generator/resources/xsd/database.xsd

Not sure what else you need to assist.

<database name="default" defaultIdMethod="native"
           namespace="App\Database"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="https://raw.githubusercontent.com/propelorm/Propel/master/generator/resources/xsd/database.xsd"
        >
</database>

VSCode details
Version: 1.36.0 (user setup)
Commit: 0f3794b38477eea13fb47fbe15a42798e6129338
Date: 2019-07-03T13:25:46.372Z
Electron: 4.2.5
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.17763

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.