This commit is contained in:
Andy Bunce 2022-03-07 16:37:26 +00:00
parent 475943053c
commit cfc8ba3817
6 changed files with 164 additions and 158 deletions

5
src/CHANGELOG.md Normal file
View file

@ -0,0 +1,5 @@
# 0.0.48
* Fix xmlToText #6
* FIX outline all vars
# 0.0.47

View file

@ -1,4 +1,4 @@
export * from "./formatAsXml";
export * from "./minifyXml";
export * from "./xmlToText";
export * from "./textToXml";

View file

@ -1,33 +0,0 @@
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, Selection } from "vscode";
import { NativeCommands } from "../../common";
import * as constants from "../../constants";
import { XmlFormatterFactory } from "../xml-formatter";
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
export function textToXml(textEditor: TextEditor): void {
textEditor.edit(textEdit => {
const selections = textEditor.selections;
selections.forEach(selection => {
if (selection.isEmpty) {
selection = new Selection(
textEditor.document.positionAt(0),
textEditor.document.positionAt(textEditor.document.getText().length)
);
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&amp;/g, "&")
// tslint:disable-next-line
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");
textEdit.replace(selection, transformed);
});
});
}

View file

@ -1,12 +1,7 @@
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, Selection } from "vscode";
import { NativeCommands } from "../../common";
import * as constants from "../../constants";
import { Range, TextEditor, Selection } from "vscode";
import { XmlFormatterFactory } from "../xml-formatter";
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
export function xmlToText(textEditor: TextEditor): void {
textEditor.edit(textEdit => {
@ -20,9 +15,9 @@ export function xmlToText(textEditor: TextEditor): void {
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/&/g, "&amp;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&apos;");
@ -30,3 +25,27 @@ export function xmlToText(textEditor: TextEditor): void {
});
});
}
export function textToXml(textEditor: TextEditor): void {
textEditor.edit(textEdit => {
const selections = textEditor.selections;
selections.forEach(selection => {
if (selection.isEmpty) {
selection = new Selection(
textEditor.document.positionAt(0),
textEditor.document.positionAt(textEditor.document.getText().length)
);
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&amp;/g, "&")
// tslint:disable-next-line
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");
textEdit.replace(selection, transformed);
});
});
}

View file

@ -5,12 +5,12 @@ import { channel } from "../common/logger";
//
// This class handles Symbols
//
function makeSymbol (name :string,desc :string,icon :vscode.SymbolKind,pos :any) {
function makeSymbol(name: string, description: string, icon: vscode.SymbolKind, pos: any) {
const spos = new vscode.Position(pos.sl, pos.sc);
const epos = new vscode.Position(pos.el, pos.ec);
const fullrange=new vscode.Range(spos,epos);
const selrange=new vscode.Range(spos,spos);
return new vscode.DocumentSymbol(name,"var", vscode.SymbolKind.Variable, fullrange, selrange);
const fullrange = new vscode.Range(spos, epos);
const selrange = new vscode.Range(spos, spos);
return new vscode.DocumentSymbol(name, description, icon, fullrange, selrange);
}
export class Symbols implements vscode.DocumentSymbolProvider {
@ -23,23 +23,23 @@ export class Symbols implements vscode.DocumentSymbolProvider {
const symbols: vscode.DocumentSymbol[] = [];
const text = document.getText();
const linter = new (XQLint as any)(text, { "styleCheck": false });
const xqdoc= linter.getXQDoc();
channel.log(xqdoc.variables);
const xqdoc = linter.getXQDoc();
channel.log("got xqdoc");
// type: type,
// pos: pos,
// qname: qname,
// annotations: {}
xqdoc.variables.forEach(v => {
const name = v.name;
const info =makeSymbol(name,"var", vscode.SymbolKind.Variable,v.pos)
symbols.push(info);
xqdoc.variables.forEach(v => {
const name = v.name;
const info = makeSymbol(name, "var", vscode.SymbolKind.Variable, v.pos)
symbols.push(info);
});
xqdoc.functions.forEach(v => {
const name = v.name;
const info =makeSymbol(name,"Fu", vscode.SymbolKind.Function,v.pos)
symbols.push(info);
xqdoc.functions.forEach(v => {
const name = v.name;
const info = makeSymbol(name, "Fu", vscode.SymbolKind.Function, v.pos)
symbols.push(info);
});
channel.log("Symbols done" + document.uri);
channel.log("Symbols done " + document.uri);
return symbols;
};
}