Skip to content

Commit

Permalink
Update initializationOptions per recent LS changes
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jul 27, 2022
1 parent 8452576 commit f039636
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 23 deletions.
6 changes: 3 additions & 3 deletions docs/settings-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The `terraform-ls.terraformExec` settings have been moved to the `terraform` sec
</tr>
</table>

All settings previously under the `terraform-ls` section have been moved to the `terraform` section:
All settings previously under the `terraform-ls` section have been moved to the `terraform` section and a new `indexing` subsection:

<table>
<tr><td>Old</td><td>New</td></tr>
Expand All @@ -87,8 +87,8 @@ All settings previously under the `terraform-ls` section have been moved to the

```json
"terraform.languageServer.rootModules": [],
"terraform.languageServer.excludeRootModules": [],
"terraform.languageServer.ignoreDirectoryNames": []
"terraform.languageServer.indexing.ignorePaths": [],
"terraform.languageServer.indexing.ignoreDirectoryNames": []
```

</td>
Expand Down
27 changes: 23 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
},
"default": [],
"description": "Per-workspace list of module directories for the language server to read",
"deprecationMessage": "Deprecated: This setting is not used by the extension and will be removed in a future release"
"deprecationMessage": "Deprecated: This setting is not used by the extension and will be removed in a future release. Add a folder/path to your workspace instead, if you wish it to be indexed."
},
"terraform.languageServer.excludeRootModules": {
"scope": "machine",
Expand All @@ -345,9 +345,28 @@
},
"default": [],
"description": "Per-workspace list of module directories for the language server to exclude",
"deprecationMessage": "Deprecated: This setting is not used by the extension and will be removed in a future release"
"deprecationMessage": "Moved: Use `#terraform.languageServer.indexing.ignorePaths#` instead."
},
"terraform.languageServer.indexing.ignorePaths": {
"scope": "machine",
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Per-workspace list of paths for the language server to ignore when indexing files"
},
"terraform.languageServer.ignoreDirectoryNames": {
"scope": "machine",
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Per-workspace list of directory names for the language server to ignore when indexing files",
"deprecationMessage": "Moved: Use `#terraform.languageServer.indexing.ignoreDirectoryNames#` instead."
},
"terraform.languageServer.indexing.ignoreDirectoryNames": {
"scope": "machine",
"type": "array",
"items": {
Expand Down Expand Up @@ -392,7 +411,7 @@
},
"default": [],
"description": "Per-workspace list of module directories for the language server to exclude",
"markdownDeprecationMessage": "Moved: Use `#terraform.languageServer.excludeRootModules#` instead"
"markdownDeprecationMessage": "Moved: Use `#terraform.languageServer.indexing.ignorePaths#` instead"
},
"terraform-ls.ignoreDirectoryNames": {
"scope": "window",
Expand All @@ -402,7 +421,7 @@
},
"default": [],
"description": "Per-workspace list of directory names for the language server to ignore when indexing files",
"markdownDeprecationMessage": "Moved: Use `#terraform.languageServer.ignoreDirectoryNames#` instead"
"markdownDeprecationMessage": "Moved: Use `#terraform.languageServer.indexing.ignoreDirectoryNames#` instead"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ async function migrateLegacySettings(ctx: vscode.ExtensionContext) {

// This simultaneously moves terraform-ls to terraform as well as migrate setting names
await migrate('terraform-ls', 'rootModules', 'languageServer.rootModules');
await migrate('terraform-ls', 'excludeRootModules', 'languageServer.excludeRootModules');
await migrate('terraform-ls', 'ignoreDirectoryNames', 'languageServer.ignoreDirectoryNames');
await migrate('terraform-ls', 'excludeRootModules', 'languageServer.indexing.ignorePaths');
await migrate('terraform-ls', 'ignoreDirectoryNames', 'languageServer.indexing.ignoreDirectoryNames');
await migrate('terraform-ls', 'terraformExecPath', 'languageServer.terraform.path');
await migrate('terraform-ls', 'terraformExecTimeout', 'languageServer.terraform.timeout');
await migrate('terraform-ls', 'terraformLogFilePath', 'languageServer.terraform.logFilePath');
Expand Down
52 changes: 38 additions & 14 deletions src/utils/clientHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,61 @@ export async function getServerOptions(lsPath: ServerPath): Promise<ServerOption
return serverOptions;
}

interface InitializationOptions {
indexing?: IndexingOptions;
experimentalFeatures?: ExperimentalFeatures;
ignoreSingleFileWarning?: boolean;
terraform?: TerraformOptions;
}

interface TerraformOptions {
path: string;
timeout: string;
logFilePath: string;
}

interface IndexingOptions {
ignoreDirectoryNames: string[];
ignorePaths: string[];
}

interface ExperimentalFeatures {
validateOnSave: boolean;
prefillRequiredFields: boolean;
}

export function getInitializationOptions() {
/*
This is basically a set of settings masquerading as a function. The intention
here is to make room for this to be added to a configuration builder when
we tackle #791
*/
const terraformExecPath = config('terraform').get<string>('languageServer.terraform.path', '');
const terraformExecTimeout = config('terraform').get<string>('languageServer.terraform.timeout', '');
const terraformLogFilePath = config('terraform').get<string>('languageServer.terraform.logFilePath', '');
const ignoreDirectoryNames = config('terraform').get<string[]>('languageServer.ignoreDirectoryNames', []);
const terraform = config('terraform').get<TerraformOptions>('languageServer.terraform', {
path: '',
timeout: '',
logFilePath: '',
});
const indexing = config('terraform').get<IndexingOptions>('languageServer.indexing', {
ignoreDirectoryNames: [],
ignorePaths: [],
});
const ignoreSingleFileWarning = config('terraform').get<boolean>('languageServer.ignoreSingleFileWarning', false);
const experimentalFeatures = config('terraform').get('experimentalFeatures');
const experimentalFeatures = config('terraform').get<ExperimentalFeatures>('experimentalFeatures');

// deprecated
const rootModulePaths = config('terraform').get<string[]>('languageServer.rootModules', []);
const excludeModulePaths = config('terraform').get<string[]>('languageServer.excludeRootModules', []);
if (rootModulePaths.length > 0 && excludeModulePaths.length > 0) {
if (rootModulePaths.length > 0 && indexing.ignorePaths.length > 0) {
throw new Error(
'Only one of rootModules and excludeRootModules can be set at the same time, please remove the conflicting config and reload',
'Only one of rootModules and indexing.ignorePaths can be set at the same time, please remove the conflicting config and reload',
);
}

const initializationOptions = {
const initializationOptions: InitializationOptions = {
experimentalFeatures,
ignoreSingleFileWarning,
...(terraformExecPath.length > 0 && { terraformExecPath }),
...(terraformExecTimeout.length > 0 && { terraformExecTimeout }),
...(terraformLogFilePath.length > 0 && { terraformLogFilePath }),
terraform,
...(rootModulePaths.length > 0 && { rootModulePaths }),
...(excludeModulePaths.length > 0 && { excludeModulePaths }),
...(ignoreDirectoryNames.length > 0 && { ignoreDirectoryNames }),
indexing,
};

return initializationOptions;
Expand Down

0 comments on commit f039636

Please sign in to comment.