Skip to content

Commit

Permalink
refactor: Removed custom support for importing headerfiles in c/c++ f…
Browse files Browse the repository at this point in the history
…iles (Reason: Made c/c++ extension a dependency that provide the same functionlity out of the box)

Signed-off-by: MdSahil-oss <mohdssahil1@gmail.com>
  • Loading branch information
MdSahil-oss authored and craciunoiuc committed Mar 22, 2024
1 parent df9dd4b commit a47d648
Show file tree
Hide file tree
Showing 23 changed files with 13 additions and 301 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ Currently, LSP provide following features:
* Auto-Completion for headerfile paths when importing in C/C++ files (Displays a list of available `*.h` files in `$PWD/.unikraft`).
* Validates if null or repeated imports are there in `C/C++` files.

### Note:

* To enable `C/C++` auto-completion or validation feature provided by LSP enable `unikraft.enableCCompletion` attribute in `$PWD/.vscode/settings.json` file. By default this attribute is set by extension itself based on the installation of [`C/C++ Extension` provided by microsoft](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) on the host machine.
* LSP server read `C_Cpp.default.includePath` attribute from `$PWD/.vscode/settings.json` file set by client to show a list of headerfiles to user present in `$PWD/.unikraft` dir to include when user imports headerfile in any `C/C++` file.

### Auto-Completion

LSP provide auto-completion feature for all the attributes of `Kraftfile` and only for importing in `C/C++` files.
Expand Down Expand Up @@ -243,10 +238,6 @@ LSP provide Hover feature only for all the attributes of `Kraftfile`.

LSP provide validation feature against null value of any attribute in `Kraftfile`.

#### `C/C++` file imports Validation

![C/C++ validation](https://github.com/unikraft/ide-vscode/blob/main/media/c-validation.gif)

## Known Issues

* The `External libraries` view is not automatically updated when the following are changed manually:
Expand Down
4 changes: 0 additions & 4 deletions client/src/UnikraftExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { env } from 'process';
import { basename } from 'path';
import { existsSync, readFileSync, rmSync } from 'fs';
import { sync as commandExistsSync } from 'command-exists';
import { enableCCompletion } from './config'

export class UnikraftExtension {
constructor(private context: vscode.ExtensionContext) { }
Expand Down Expand Up @@ -122,9 +121,6 @@ export class UnikraftExtension {

await reloadIncludes(projectPath);
await reloadConfig(projectPath);

// Checking if `C/C++` Extension is installed on the system.
await enableCCompletion();
}

private initExtension() {
Expand Down
23 changes: 0 additions & 23 deletions client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
import { ConfigurationTarget, workspace } from 'vscode';
import { execSync } from "child_process";

// enableCCompletion set `enableCCompletion` to true if `C/C++ Extension` is not installed on the system.
export async function enableCCompletion() {
let installedExts: string = "";

// Try to fetch all the installed extension names on the system.
installedExts = execSync('code --list-extensions').toString();

// Checks, If `C/C++ Extension` (ID: ms-vscode.cpptools) provided by microsoft already exist.
// If so, then update the workspace configuration with `enableCCompletion: false`
// Otherwise, set it to `enableCCompletion: true` to enable server's custom headerfiles completion.
let confUnikraft = workspace.getConfiguration().get("unikraft");
if (confUnikraft === null || confUnikraft === undefined) {
await workspace.getConfiguration().update("unikraft", {
"enableCCompletion": !installedExts.includes("ms-vscode.cpptools")
}, ConfigurationTarget.Workspace);
confUnikraft = workspace.getConfiguration().get("unikraft");
} else {
confUnikraft["enableCCompletion"] = !installedExts.includes("ms-vscode.cpptools");
await workspace.getConfiguration().update("unikraft", confUnikraft, ConfigurationTarget.Workspace);
}
}

// provideDefaultConfigC checks & provide default configuations for c/c++.
export async function provideDefaultConfigC() {
Expand Down
2 changes: 0 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export async function activate(context: ExtensionContext) {
// { scheme: 'file', language: 'plaintext' },
{ pattern: '*.y(a)ml' },
{ scheme: 'file', language: 'yaml' },
{ scheme: 'file', language: 'cpp' },
{ scheme: 'file', language: 'c' }
],
synchronize: {
// Notify the server about file changes to '.clientrc' files contained in the workspace.
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
}
},
"unikraft": {
"enableCCompletion": {
"type": "boolean",
"default": false,
"description": "Enables Server to show auto-completion elements for headerfiles in `.c/.h` extension files, By default it checks host machine if `C/C++ Extension` provided by microsoft is installed and sets itself."
},
"client": {
"sources": {
"type": "string",
Expand Down
27 changes: 0 additions & 27 deletions server/src/c/complete.ts

This file was deleted.

71 changes: 0 additions & 71 deletions server/src/c/complete/import.ts

This file was deleted.

20 changes: 0 additions & 20 deletions server/src/c/utils.ts

This file was deleted.

18 changes: 0 additions & 18 deletions server/src/c/validate.ts

This file was deleted.

74 changes: 0 additions & 74 deletions server/src/c/validate/import.ts

This file was deleted.

2 changes: 1 addition & 1 deletion server/src/kraftfile/attributes/unikraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'vscode-languageserver/node'

import { HoverItem } from '../types';
import { codeBlockStr, minimalKraftfile, reTriggerCompletionCMD } from '../utils';
import { codeBlockStr, minimalKraftfile } from '../utils';
import { unikraft } from "../../utils";

const label: string = "unikraft";
Expand Down
4 changes: 1 addition & 3 deletions server/src/kraftfile/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ import { platformValueCompletionItem } from './values/targets';
import { getCurrentWordFromYamlFile } from '../utils';
import { targetsValueCompletionItem } from './values/targets';

const yaml = require("yaml");

export function kraftfileCompletionItems(currentUriText: string, workspaceDir: string, params: TextDocumentPositionParams): CompletionItem[] {
let items: CompletionItem[] = [];
const lines = currentUriText.split('\n');
let lineStr = lines[params.position.line];
const lineStr = lines[params.position.line];
let isValue: boolean = false;
let isNested: boolean = false;
let paretnAttribute: string = "";
Expand Down
2 changes: 1 addition & 1 deletion server/src/kraftfile/validate/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validateCmd(document: TextDocument, kraftfile: KraftYamlType): D
return []
}

let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];
const docText = document.getText();
const alertPos = docText.indexOf("cmd");
const emptyWarning = {
Expand Down
2 changes: 1 addition & 1 deletion server/src/kraftfile/validate/libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validateLibraries(document: TextDocument, kraftfile: KraftYamlTy
return [];
}

let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];
const docText = document.getText();
const emptyWarning: string = `Warning: Empty value.`;

Expand Down
2 changes: 1 addition & 1 deletion server/src/kraftfile/validate/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validateName(document: TextDocument, kraftfile: KraftYamlType):
return [];
}

let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];
const docText = document.getText();
const alertPos = docText.indexOf("name");
const emptyWarning = {
Expand Down
2 changes: 1 addition & 1 deletion server/src/kraftfile/validate/rootfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validateRootfs(document: TextDocument, kraftfile: KraftYamlType)
return [];
}

let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];
const docText = document.getText();
const alertPos = docText.indexOf("rootfs");
const emptyWarning = {
Expand Down
2 changes: 1 addition & 1 deletion server/src/kraftfile/validate/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validateRuntime(document: TextDocument, kraftfile: KraftYamlType
return [];
}

let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];
const docText = document.getText();
const alertPos = docText.indexOf("runtime");
const emptyWarning = {
Expand Down
4 changes: 2 additions & 2 deletions server/src/kraftfile/validate/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export function validateTemplate(document: TextDocument, kraftfile: KraftYamlTyp
return [];
}

let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];
const docText = document.getText();
let tempAlertPos = docText.indexOf("template");
const tempAlertPos = docText.indexOf("template");
const warnMsg = `Warning: Empty value.`
const emptyWarning = {
severity: DiagnosticSeverity.Warning,
Expand Down
2 changes: 1 addition & 1 deletion server/src/kraftfile/validate/volumes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validateVolumes(document: TextDocument, kraftfile: KraftYamlType
return [];
}

let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];
const docText = document.getText();
const volumesAlertPos = docText.indexOf("volumes");
const warnMsg = `Warning: Empty value.`;
Expand Down
Loading

0 comments on commit a47d648

Please sign in to comment.