Skip to content

Commit

Permalink
Merge pull request #125 from redhat-developer/printWidthSetting
Browse files Browse the repository at this point in the history
Added printWidth setting
  • Loading branch information
JPinkney authored Feb 18, 2019
2 parents de812c9 + 57f55e7 commit 99f85cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/languageservice/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ export interface SchemaConfiguration {
}

export interface CustomFormatterOptions {
singleQuote?: boolean;
bracketSpacing?: boolean;
proseWrap?: string;
singleQuote?: boolean;
bracketSpacing?: boolean;
proseWrap?: string;
printWidth?: number;
}

export interface LanguageService {
Expand Down
10 changes: 5 additions & 5 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ export let customLanguageService = getCustomLanguageService(schemaRequestService
// The settings interface describes the server relevant settings part
interface Settings {
yaml: {
format: CustomFormatterOptions & {
enable: boolean;
};
format: CustomFormatterOptions;
schemas: JSONSchemaSettings[];
validate: boolean;
hover: boolean;
Expand Down Expand Up @@ -200,7 +198,8 @@ let yamlShouldValidate = true;
let yamlFormatterSettings = {
singleQuote: false,
bracketSpacing: true,
proseWrap: "preserve"
proseWrap: "preserve",
printWidth: 80
} as CustomFormatterOptions;
let yamlShouldHover = true;
let yamlShouldCompletion = true;
Expand All @@ -225,7 +224,8 @@ connection.onDidChangeConfiguration((change) => {
if (settings.yaml.format) {
yamlFormatterSettings = {
singleQuote: settings.yaml.format.singleQuote || false,
proseWrap: settings.yaml.format.proseWrap || "preserve"
proseWrap: settings.yaml.format.proseWrap || "preserve",
printWidth: settings.yaml.format.printWidth || 80
};
if (settings.yaml.format.bracketSpacing === false) {
yamlFormatterSettings.bracketSpacing = false;
Expand Down
10 changes: 10 additions & 0 deletions test/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ suite("Formatter Tests", () => {
assert.notEqual(edits.length, 0);
});

it('Formatting wraps text', () => {
let content = `comments: >
test test test test test test test test test test test test`;
let testTextDocument = setup(content);
let edits = languageService.doFormat(testTextDocument, {
printWidth: 20,
proseWrap: "always"
});
assert.equal(edits[0].newText, "comments: >\n test test test\n test test test\n test test test\n test test test\n");
});
});

});
Expand Down

0 comments on commit 99f85cb

Please sign in to comment.